pandas index_col=“datetime” makes df['datetime'] unavailable

The title says it all. The following bit of pseudo-code returns the following error:

df = pd.read_sql(query, conn, parse_dates=["datetime"],
                             index_col="datetime")
df['datetime']

I get :

Exception in thread Thread-1:
 Traceback (most recent call last):
   File "C:\Users\admin\.virtualenvs\EnkiForex-ey09TNOL\lib\site-packages\pandas\core\indexes\base.py", line 2656, in get_loc
     return self._engine.get_loc(key)
   File "pandas\_libs\index.pyx", line 108, in pandas._libs.index.IndexEngine.get_loc
   File "pandas\_libs\index.pyx", line 132, in pandas._libs.index.IndexEngine.get_loc
   File "pandas\_libs\hashtable_class_helper.pxi", line 1601, in pandas._libs.hashtable.PyObjectHashTable.get_item
   File "pandas\_libs\hashtable_class_helper.pxi", line 1608, in pandas._libs.hashtable.PyObjectHashTable.get_item
 KeyError: 'datetime'

Am I misunderstanding what's going on by indexing the datetime col? I can access all the other columns normally though.

#python

1 Likes2.50 GEEK