Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

raise KeyError(key) from err

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 ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It is because you set your dataframe index as PassengerId on this part.

dt = pd.read_csv("./titanic.csv", index_col=["PassengerId"])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading