Python 我想重置索引,但想在dataframe中拥有所有列

Python 我想重置索引,但想在dataframe中拥有所有列,python,pandas,dataframe,Python,Pandas,Dataframe,我的索引是datetime,但我希望将默认索引从0,1…设置为n,但希望将我的datetime索引保留为dataframe中的列 reset_index会删除索引,我无法将datetime作为列获取 我该怎么做 a b ... c d DateTime ...

我的索引是datetime,但我希望将默认索引从0,1…设置为n,但希望将我的datetime索引保留为dataframe中的列

reset_index会删除索引,我无法将datetime作为列获取

我该怎么做

                          a       b           ...          c         d
DateTime                                      ...                       

2016-07-01 00:00:00  994.758209  31.556425    ...          NaN       NaN

2016-07-01 12:00:00  994.727417  29.273750    ...          NaN       NaN

2016-07-02 00:00:00  996.516484  26.598056    ...          NaN       NaN

2016-07-04 00:00:00  997.588235  10.686389    ...          NaN       NaN

2016-07-04 12:00:00  994.347107  25.472639    ...          NaN       NaN
df.reset_索引不应删除DateTime列


如果这不能解决问题,请在原始问题中发布您的代码。

df=df.reset\u index不起作用?@jezrael它起作用,但正如我告诉datetime是我的索引,因此它从数据帧中删除,但我想将其保留为列,并添加一个正常的索引值,如0,1,ndf['date']=df.index,然后重置索引?我把我的错放在适当的地方=真的
df = pd.read_csv('data.csv', parse_dates=['DateTime'], index_col='DateTime')

                             a          b
           DateTime     
2016-07-01 00:00:00 994.758209  31.556425
2016-07-01 12:00:00 994.727417  29.273750
2016-07-02 00:00:00 996.516484  26.598056
2016-07-04 00:00:00 997.588235  10.686389
2016-07-04 12:00:00 994.347107  25.472639

df.info()

<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 5 entries, 2016-07-01 00:00:00 to 2016-07-04 12:00:00
Data columns (total 2 columns):
a    5 non-null float64
b    5 non-null float64
dtypes: float64(2)

df = df.reset_index()

               DateTime          a          b
0   2016-07-01 00:00:00 994.758209  31.556425
1   2016-07-01 12:00:00 994.727417  29.273750
2   2016-07-02 00:00:00 996.516484  26.598056
3   2016-07-04 00:00:00 997.588235  10.686389
4   2016-07-04 12:00:00 994.347107  25.472639