【发布时间】:2020-09-29 13:16:00
【问题描述】:
请你看一下好吗?我试图在我的数据框中有一个索引为 1980-12-12 的列,所以基本上是日期。目前,当我尝试选择此列时,我无法定位它。
我知道如何为 csv/excel 文件执行此操作,但如何索引/创建日期为 1980-12-12 的列?
谢谢!
为我的体积图获取数据的功能:
from yahooquery import Ticker
def getVolumeGraph():
aapl = Ticker('aapl')
df = aapl.history(period='max', interval='1d')
print(df.info())
print(df)
#return fig
df
high close ... dividends splits
1980-12-12 14:30:00 0.515625 0.513393 ... 0.0 0.0
1980-12-15 14:30:00 0.488839 0.486607 ... 0.0 0.0
1980-12-16 14:30:00 0.453125 0.450893 ... 0.0 0.0
1980-12-17 14:30:00 0.464286 0.462054 ... 0.0 0.0
1980-12-18 14:30:00 0.477679 0.475446 ... 0.0 0.0
... ... ... ... ... ...
2020-06-03 13:30:00 326.200012 325.119995 ... 0.0 0.0
2020-06-04 13:30:00 325.619995 322.320007 ... 0.0 0.0
2020-06-05 13:30:00 331.750000 331.500000 ... 0.0 0.0
2020-06-08 13:30:00 333.600006 333.459991 ... 0.0 0.0
2020-06-09 13:30:00 345.609985 343.989990 ... 0.0 0.0
df.info()
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 9957 entries, 1980-12-12 14:30:00 to 2020-06-09 13:30:00
Data columns (total 8 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 high 9957 non-null float64
1 close 9957 non-null float64
2 low 9957 non-null float64
3 volume 9957 non-null float64
4 open 9957 non-null float64
5 adjclose 9957 non-null float64
6 dividends 9957 non-null float64
7 splits 9957 non-null float64
dtypes: float64(8)
memory usage: 1020.1 KB
【问题讨论】:
-
df.index.date? -
“你不能定位它”是什么意思?期望的输出是什么?
-
不是列,是df的索引。
df.info()对您来说非常明显:“DatetimeIndex:9957 个条目,1980-12-12 14:30:00 到 2020-06-09 13:30:00” -
哦,是的,早上的心灵打击。谢谢大家。