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
775 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 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,520 points
5,489 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,520 points

edited Dec 10, 2018 by Nymeria 98 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
• 67,380 points
149 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
99 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
702 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
1,289 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,520 points
1,169 views