Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pandas: cannot do positional indexing on DatetimeIndex with these indexers [2016-08-01 00:00:00] of Timestamp

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 ?

like image 539
Homunculus Reticulli Avatar asked Jul 29 '17 15:07

Homunculus Reticulli


1 Answers

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']
like image 151
Psidom Avatar answered Oct 20 '22 16:10

Psidom