4

I'm wondering how to get the Date column values. The 'Date' column doesn't show when typing df.columns. I'm trying to get this df into a Json file with df.to_json(), which get all values but the Date. Thank you all.

             Open   High    Low  Close
Date
2020-03-16  36.01  41.40  36.01  39.04
2020-03-17  40.50  43.57  39.11  41.51
2020-03-18  38.80  40.87  35.70  38.65
2020-03-19  37.50  39.00  35.26  36.40
2020-03-20  37.90  39.41  34.71  35.19

In [49]: type(df) Out[49]: pandas.core.frame.DataFrame

0

2 Answers 2

11

Looks like Date is currently in the index. If you would like it to be a column, you just have to reset the index:

df.reset_index(inplace=True)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I didn't know I could have values on the index. You were really helpful! :)
1

It doesn't appear because it's not really a column, it's the index. It shouldn't matter, however, because by default, df.to_json() will by default include the index. It says so in the docs.

1 Comment

Thank you! Some how it's not including. But if I reset_index like @kgoettler said above it worked! :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.