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?
You can use the update method to directly overwrite it in place.
df.update(calc)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With