I a newbie using pandas, I am trying to access my (date indexed) dataframe df
using code similar to this:
for idx, row in df.iterrows():
if idx < startrow:
continue
col1_data = df.iloc[idx]['col1']
I get the following error:
cannot do positional indexing on <class 'pandas.core.indexes.datetimes.DatetimeIndex'> with these indexers [2016-08-01 00:00:00] of <class 'pandas._libs.tslib.Timestamp'>
How do I fix this ?
The iloc
needs to be loc
, as the former is integer-location based indexing; To select rows by labels (or the actual index as is idx
) you need loc
:
col1_data = df.loc[idx]['col1']
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