我正在努力处理一些股票市场数据。我有以下DataFrame:
>>> ticker
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 707 entries, 2010-01-04 00:00:00 to 2012-10-19 00:00:00
Data columns:
Open 707 non-null values
High 707 non-null values
Low 707 non-null values
Close 707 non-null values
Volume 707 non-null values
Adj Close 707 non-null values
dtypes: float64(5), int64(1)
我会引用随机收盘价:
>>> ticker ['Close'] [704]
21.789999999999999
获取第704个项目日期的语法是什么?
同样,我如何获得以下项目数组中的位置?:
>>> ticker.Close.min ()
17.670000000000002
我知道这看起来非常基本,但我花了很多时间搜索文档。如果它在那里,我绝对错过它。
答案 0 :(得分:3)
这应该回答你的两个问题:
注意:如果你想要第704个元素,你应该使用“703”作为索引从零开始。如您所见df['A'].argmin()
也返回1,这是df中的第二行。
In [682]: print df
A B C
2000-01-01 1.073247 -1.784255 0.137262
2000-01-02 -0.797483 0.665392 0.692429
2000-01-03 0.123751 0.532109 0.814245
2000-01-04 1.045414 -0.687119 -0.451437
2000-01-05 0.594588 0.240058 -0.813954
2000-01-06 1.104193 0.765873 0.527262
2000-01-07 -0.304374 -0.894570 -0.846679
2000-01-08 -0.443329 -1.437305 -0.316648
In [683]: df.index[3]
Out[683]: <Timestamp: 2000-01-04 00:00:00>
In [684]: df['A'].argmin()
Out[684]: 1