How to access pandas DataFrame datetime index using strings

pandas is taking what’s inside the [] and deciding what it should do. If it’s a subset of column names, it’ll return a DataFrame with those columns. If it’s a range of index values, it’ll return a subset of those rows. What is does not handle is taking a single index value.

Solution

Two work around’s

1.Turn the argument into something pandas interprets as a range.

df['2008-01-01':'2008-01-01']

2.Use the method designed to give you this result. loc[]

df.loc['2008-01-01']

Link to the documentation

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)