'DataFrame' 对象没有属性 'DatetimeIndex'
'DataFrame' object has no attribute 'DatetimeIndex'
我正在尝试 return Pandas 日期已设置为 DateTimeIndex。我试过很多类似
的东西
inx=OutputDataSet.DatetimeIndex.to_pydatetime()
或
inx=OutputDataSet.DatetimeIndex.to_pydatetime(format =''%y-%m-%d'')
但我一直收到错误
'DataFrame' object has no attribute 'DatetimeIndex'
这是信息属性显示的内容;
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 1047 entries, 2017-01-03 to 2021-02-19
Data columns (total 6 columns):
Open 1047 non-null float64
High 1047 non-null float64
Low 1047 non-null float64
Close 1047 non-null float64
Adj Close 1047 non-null float64
Volume 1047 non-null int64
dtypes: float64(5), int64(1)
memory usage: 57.3 KB
很明显有一个DatetimeIndex
打印输出没有问题显示 DatetimeIndex
Open High ... Adj Close Volume
Date ...
2017-01-03 2.870000 2.940000 ... 2.842312 146804
2017-01-04 2.950000 3.090000 ... 2.871415 292371
2017-01-05 3.000000 3.000000 ... 2.871415 186374
2017-01-06 2.950000 2.970000 ... 2.764707 141723
2017-01-09 2.900000 2.970000 ... 2.842312 60815
理想情况下,我希望 DataFrame 呈现为
Date 1047 non-null datetime
Open 1047 non-null float64
High 1047 non-null float64
Low 1047 non-null float64
Close 1047 non-null float64
Adj Close 1047 non-null float64
Volume 1047 non-null int64
任何帮助将不胜感激
我认为 DatetimeIndex
是您 pandas.DataFrame 上的索引类型。每个 DataFrame
都带有 属性 index
和 index
可以是从 DateTimeIndex
到 PeriodIndex
和 TimedeltaIndex
的不同类型(guide here)
因此在您的输出中,Date
是您的索引。如果这不是您期望的输出,您可能需要重新考虑使用 pandas DataFrame。
解决方法如下;
OutputDataSet.insert(loc=0,column=''Date'', value=pd.to_datetime(OutputDataSet.index))
我正在尝试 return Pandas 日期已设置为 DateTimeIndex。我试过很多类似
的东西inx=OutputDataSet.DatetimeIndex.to_pydatetime()
或
inx=OutputDataSet.DatetimeIndex.to_pydatetime(format =''%y-%m-%d'')
但我一直收到错误
'DataFrame' object has no attribute 'DatetimeIndex'
这是信息属性显示的内容;
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 1047 entries, 2017-01-03 to 2021-02-19
Data columns (total 6 columns):
Open 1047 non-null float64
High 1047 non-null float64
Low 1047 non-null float64
Close 1047 non-null float64
Adj Close 1047 non-null float64
Volume 1047 non-null int64
dtypes: float64(5), int64(1)
memory usage: 57.3 KB
很明显有一个DatetimeIndex
打印输出没有问题显示 DatetimeIndex
Open High ... Adj Close Volume
Date ...
2017-01-03 2.870000 2.940000 ... 2.842312 146804
2017-01-04 2.950000 3.090000 ... 2.871415 292371
2017-01-05 3.000000 3.000000 ... 2.871415 186374
2017-01-06 2.950000 2.970000 ... 2.764707 141723
2017-01-09 2.900000 2.970000 ... 2.842312 60815
理想情况下,我希望 DataFrame 呈现为
Date 1047 non-null datetime
Open 1047 non-null float64
High 1047 non-null float64
Low 1047 non-null float64
Close 1047 non-null float64
Adj Close 1047 non-null float64
Volume 1047 non-null int64
任何帮助将不胜感激
我认为 DatetimeIndex
是您 pandas.DataFrame 上的索引类型。每个 DataFrame
都带有 属性 index
和 index
可以是从 DateTimeIndex
到 PeriodIndex
和 TimedeltaIndex
的不同类型(guide here)
因此在您的输出中,Date
是您的索引。如果这不是您期望的输出,您可能需要重新考虑使用 pandas DataFrame。
解决方法如下;
OutputDataSet.insert(loc=0,column=''Date'', value=pd.to_datetime(OutputDataSet.index))