1

I have dataframe which look like this:

2000-01-03               4653.1
2000-01-10               4657.6
2000-01-17               4659.8
2000-01-24               4667.0
2000-01-31               4667.7
                        ...
2020-06-08              18248.9
2020-06-15              18329.3
2020-06-22              18429.5
2020-06-29              18424.6
2020-07-06              18522.1

[1071 rows x 1 columns]

I want to name the index column Date but i cannot set_index because it does not have a name. how can i set the name of index column when it does not have name?

Slartibartfast
  • 1,058
  • 4
  • 26
  • 60

2 Answers2

2

Use pd.DataFrame.rename_axis

df = df.rename_axis('Date')
Scott Boston
  • 147,308
  • 15
  • 139
  • 187
1

The name of the index can be set with its name property.

df.index.name = 'Date'
dannyadam
  • 3,950
  • 2
  • 22
  • 19