aabujamra
aabujamra

Reputation: 4636

Python/Pandas - ValueError: Incompatible indexer with Series

I have a dataframe:

df:

        A      B 
id
 3   'Yes'    23
 5   'Yes'    67
 6    'No'    56
 8    'No'    23

I have another dataframe:

calc:
       A    B
id   
 3   'No'   4 

I would like to update df with calc values. I'm trying to use the following:

tgsm.loc[i]=calc

However, that doesn't work. I keep getting the following error:

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/core/indexing.py", line 693, in _align_series
raise ValueError('Incompatible indexer with Series')
ValueError: Incompatible indexer with Series

If try tgsm.loc[i]=calc[i], it gets me to this other error:

File "pandas/index.pyx", line 137, in pandas.index.IndexEngine.get_loc (pandas/index.c:4154)
File "pandas/index.pyx", line 159, in pandas.index.IndexEngine.get_loc (pandas/index.c:4018)
File "pandas/hashtable.pyx", line 675, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12368)
File "pandas/hashtable.pyx", line 683, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12322)
KeyError: 3

Can anyone help enlightening my journey?

Upvotes: 4

Views: 14110

Answers (1)

Ted Petrou
Ted Petrou

Reputation: 62037

You can use the update method to directly overwrite it in place.

df.update(calc)

Upvotes: 8

Related Questions