Home > Net >  Pandas DataFrame 'Date' Column has no header / dtypes / not listed in df.columns
Pandas DataFrame 'Date' Column has no header / dtypes / not listed in df.columns

Time:07-24

I'm importing data from nasdaqdatalink api

Two questions from this:

  • (1) How is this already a Pandas DataFrame without me needing to type df = pd.DataFrame ?
  • (2) The 'Date' column, doesn't appear to be a DataFrame column? if I try df.columns it doesn't show up in the index and obviously has no header. So I am confused on what's happening here.

Essentially, I wanted to select data from this DataFrame between two dates, but the only way I really know how to do that is by selecting the column name first. However, I'm missing something here. I tried to rename the column in position [0] but that just created a new column named 'Date' with NaN values.

What am I not understanding? (I've only just begun learning Python, Pandas etc. ~1 month ago ! so this is about as far as I could go on my own without more help)

screenshot

CodePudding user response:

There's actually a better way, by keeping Date as the index, see the output of:

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

df.reset_index() makes whatever the current index is into a column.

  • Related