Python Pandas: KeyError: False

0 votes

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

May 8 in Python by Tina
43 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

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. So try this:

up_df1 = {'Name': names, 'New Points': point_list}
up_df=pd.DataFrame(up_df1)
answered May 8 by Jimmy

Related Questions In Python

0 votes
1 answer

How to convert a Pandas GroupBy object to DataFrame in Python

g1 here is a DataFrame. It has a hierarchical index, ...READ MORE

answered Nov 12, 2018 in Python by Nymeria
• 3,500 points
2,486 views
0 votes
1 answer

How to use Pandas HDF5 as a Database in Python?

HDF5 works fine for concurrent read only ...READ MORE

answered Nov 30, 2018 in Python by Nymeria
• 3,500 points

edited Dec 10, 2018 by Nymeria 48 views
0 votes
1 answer

Python pandas axis error

When you are applying sum() you don't ...READ MORE

answered Jan 8 in Python by Omkar
• 65,850 points
58 views
0 votes
1 answer
0 votes
1 answer

How to rename columns in pandas (Python)?

It is easy by just adding ".columns" ...READ MORE

answered Apr 30, 2018 in Data Analytics by DeepCoder786
• 1,700 points
54 views
0 votes
1 answer

What is the Difference in Size and Count in pandas (python)?

The major difference is size includes NaN ...READ MORE

answered Apr 30, 2018 in Data Analytics by DeepCoder786
• 1,700 points
546 views
0 votes
2 answers
0 votes
1 answer

Converting a pandas data-frame to a dictionary

Emp_dict=Employee.to_dict('records') You can directly use the 'to_dict()' function ...READ MORE

answered May 23, 2018 in Data Analytics by Bharani
• 4,550 points
720 views
0 votes
1 answer

How to replace values with None in Pandas data frame in Python?

Actually in later versions of pandas this ...READ MORE

answered Aug 30, 2018 in Python by Priyaj
• 56,120 points
289 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.