Reputation: 68396
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 ?
Upvotes: 8
Views: 15284
Reputation: 214957
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']
Upvotes: 19