Pandas,如何引用时间序列项目? [英] Pandas, How to reference Timeseries Items?
问题描述
我正在尝试处理一些股市数据.我有以下数据帧:
<预><代码>>>>股票代码<class 'pandas.core.frame.DataFrame'>日期时间索引:707 个条目,2010-01-04 00:00:00 到 2012-10-19 00:00:00数据列:打开 707 个非空值高 707 非空值低 707 非空值关闭 707 个非空值第 707 卷非空值调整关闭 707 个非空值数据类型:float64(5)、int64(1)我将参考随机收盘价:
<预><代码>>>>股票代码 ['关闭'] [704]21.789999999999999获取第 704 项日期的语法是什么?
同样,如何获得以下项在数组中的位置?:
<预><代码>>>>ticker.Close.min ()17.670000000000002我知道这看起来很基本,但我花了很多时间搜索文档.如果它在那里,我绝对想念它.
这应该能回答你的两个问题:
注意:如果你想要第 704 个元素,你应该使用703"作为索引从零开始.如您所见,df['A'].argmin()
也返回 1,即 df 中的第二行.
在[682]中:打印df乙丙2000-01-01 1.073247 -1.784255 0.1372622000-01-02 -0.797483 0.665392 0.6924292000-01-03 0.123751 0.532109 0.8142452000-01-04 1.045414 -0.687119 -0.4514372000-01-05 0.594588 0.240058 -0.8139542000-01-06 1.104193 0.765873 0.5272622000-01-07 -0.304374 -0.894570 -0.8466792000-01-08 -0.443329 -1.437305 -0.316648在 [683]: df.index[3]Out[683]:<时间戳:2000-01-04 00:00:00>在 [684]: df['A'].argmin()出[684]:1
I'm trying to work with some stock market data. I have the following 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)
I'll reference a random closing price:
>>> ticker ['Close'] [704]
21.789999999999999
What's the syntax to get the date of that 704th item?
Similarly, how do I get the position in the array of the following item?:
>>> ticker.Close.min ()
17.670000000000002
I know this seems pretty basic, but I've spent a lot of time scouring the documentation. If it's there, I'm absolutely missing it.
This should answer both your questions:
Note: if you want the 704th element, you should use "703" as index starts form zero. As you see df['A'].argmin()
also returns 1, that is the second row in the 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
这篇关于Pandas,如何引用时间序列项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!