Code
print df.at[date, 'column name']
Problem description
Since upgrading pandas to 0.21.0 and then 0.21.1, my code using fast indexing .at
isn't working anymore. I get this error:
TypeError: only integer scalar arrays can be converted to a scalar index
date
is a <class 'pandas._libs.tslib.Timestamp'>
and is in the index of the DataFrame (simple DataFrame without multi-index).
Doing type(df.index[0])
also gives me <class 'pandas._libs.tslib.Timestamp'>
Any idea? Nothing changed in the docs on .at
Thanks
Edit
I just did a simple test:
tmp = pd.dataframe(1, index=pd.date_range('2017-01-01','2017-02-02'), columns=['col1','col2'])
date = tmp.index[0]
tmp.at[date, 'col1']
and this is working... Very puzzling.
Comment From: HedgeShot
Error was coming from the DataFrame... In prior version of pandas one had to generate columns with double brackets and now not anymore. Changing it solved the issue. Old:
pd.DataFrame(columns=[['x','y','z']])
Now
pd.DataFrame(columns=['x','y','z'])
Comment From: jreback
make sure you are actually using 0.21 & you have a misspelling in your example
In [1]: pd.__version__
Out[1]: '0.21.1'
In [2]: tmp = pd.DataFrame(1, index=pd.date_range('2017-01-01','2017-02-02'), columns=['col1','col2'])
...: date = tmp.index[0]
...: tmp.at[date, 'col1']
...:
Out[2]: 1
Comment From: jreback
Error was coming from the DataFrame... In prior version of pandas one had to generate columns with double brackets and now not anymore. Changing it solved the issue.
huh? why would you do this?