Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Machine Learning by (19k points)

Hi. I have written a python pandas script

old_df = pd.read_csv('User data.csv')

up_df = {'Name': names, 'New Points': point_list}

for name in up_df['Name']:

    for old_name in old_df['Name']:

        if name==old_name:

            i=(old_df[old_df['Name']==old_name].index.values)

            j=(up_df[up_df['Name']==name].index.values)

            print(j[0])

            old_df.at[i[0],'New Points']=up_df[j[0],'New Points']

But I am getting this error at the bold line in the script above

KeyError: False

Please help

1 Answer

0 votes
by (33.1k points)

The reason for this error is that you have created a dictionary

up_df = {'Name': names, 'New Points': point_list}

but you are treating it as a pandas dataframe

j=(up_df[up_df['Name']==name].index.values)

You have to create a pandas dataframe first. 

For example:

up_df1 = {'Name': names, 'New Points': point_list}

up_df=pd.DataFrame(up_df1)

For more details on Python Pandas, study the Python Course. Also, study the Machine Learning Certification Course by Intellipaat for more details on this. Hope this answer helps you!

Browse Categories

...