Pandas时间序列

2024-05-19 07:22:31 发布

您现在位置:Python中文网/ 问答频道 /正文

数据:

date,                                             price1

2001/11/01 00:00:01am,                              10

2001/11/02 00:00:02am,                              20

2001/11/03 00:00:03am,                              15

2001/11/04 00:00:04am,                              30

使用pandas数据帧(df),我们可以通过以下方式获取第一列的值:

^{pr2}$

如果我们想打发时间,你能做什么?在

^{3}$

不起作用。在


Tags: 数据pandasdfdate方式时间pr2price1
1条回答
网友
1楼 · 发布于 2024-05-19 07:22:31
In [36]: rng = date_range('1/1/2011', periods=5, freq='H')

In [37]: df = DataFrame({'price':[1,2,3,4,5]},index = rng)

In [38]: df
Out[38]: 
                     price
2011-01-01 00:00:00      1
2011-01-01 01:00:00      2
2011-01-01 02:00:00      3
2011-01-01 03:00:00      4
2011-01-01 04:00:00      5

In [39]: df.index
Out[39]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2011-01-01 00:00:00, ..., 2011-01-01 04:00:00]
Length: 5, Freq: H, Timezone: None

In [40]: df.index.values
Out[40]: 
array([1970-01-15 104:00:00, 1970-01-15 105:00:00, 1970-01-15 106:00:00,
       1970-01-15 107:00:00, 1970-01-15 108:00:00], dtype=datetime64[ns])

相关问题 更多 >

    热门问题