我将DatetimeIndex定义如下。
>>> date_rng = pandas.date_range('20060101','20121231',freq='D')
>>> type(date_rng)
<class 'pandas.tseries.index.DatetimeIndex'>
>>> date_rng[0]
<Timestamp: 2006-01-01 00:00:00>
'date_rng'中的每个元素都是'Timestamp',如何将其转换为如下字符串系列?
>>> pandas.Series(['2006-01-01','2006-01-02','2006-01-03'])
0 2006-01-01
1 2006-01-02
2 2006-01-03
答案 0 :(得分:15)
>>> date_rng = pd.date_range('20060101','20060105',freq='D')
>>> pd.Series(date_rng.format())
0 2006-01-01
1 2006-01-02
2 2006-01-03
3 2006-01-04
4 2006-01-05