2

数据:

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

不管用。

4

1 回答 1

2
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])
于 2013-01-23T07:12:14.427 回答