I am going to itterate over the taitanic dataset. Here is the code:
import numpy as np
import pandas as pd
!wget "https://calmcode.io/datasets/titanic.csv"
dt = pd.read_csv("./titanic.csv", index_col=["PassengerId"])
def impute_cabin_values(X):
for i in range(len(X)):
print(X["Pclass"][i])
impute_cabin_values(dt)
And then i face with the following error:
raise KeyError(key) from err
KeyError: 0
why should index 0 in the print(X["Pclass"][i]) not working ?
>Solution :
It is because you set your dataframe index as PassengerId on this part.
dt = pd.read_csv("./titanic.csv", index_col=["PassengerId"])