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, 2019 in Python by Tina
10,325 views

1 answer to this question.

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, 2019 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,560 points
34,379 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,560 points

edited Dec 10, 2018 by Nymeria 1,213 views
–1 vote
1 answer

Python pandas axis error

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

answered Jan 8, 2019 in Python by Omkar
• 69,230 points
2,052 views
0 votes
1 answer

Need help using Joins in Pandas using Python

Hi, there is one scenario where the ...READ MORE

answered Jan 24, 2019 in Python by Nymeria
• 3,560 points
596 views
0 votes
1 answer

How to rename columns in pandas (Python)?

You can use the rename function in ...READ MORE

answered Apr 30, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 8, 2020 by MD 1,963 views
0 votes
1 answer

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

The major difference is "size" includes NaN values, ...READ MORE

answered Apr 30, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 8, 2020 by Gitika 2,744 views
0 votes
2 answers

Replacing a row in pandas data.frame

key error. I love python READ MORE

answered Feb 18, 2019 in Data Analytics by anonymous
13,592 views
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,660 points
4,528 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
• 58,100 points
11,574 views
–1 vote
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP