【问题标题】:Time series through pandas通过熊猫的时间序列
【发布时间】:2013-01-06 14:24:42
【问题描述】:

数据:

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),我们可以通过以下方式获取第一列的值:

df.price1

如果我们想花几天时间,你能做什么?

df.date

不工作。

【问题讨论】:

    标签: python pandas


    【解决方案1】:
    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])
    

    【讨论】:

      猜你喜欢
      • 2019-08-10
      • 1970-01-01
      • 2014-10-08
      • 2020-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多