python - 如何将 Pandas DatetimeIndex 相应地转换为字符串

标签 python pandas

我定义了一个 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

最佳答案

>>> 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

关于python - 如何将 Pandas DatetimeIndex 相应地转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12834568/

相关文章:

python - 与 Python 3.5 中的 typing.Generic 进行比较时,issubclass 是否损坏?

python - 将包含 GEOMETRY 列的表加载到 Pandas DataFrame

python - 对于不同的 CSV 文件获得相同的结果

python - 提高 Pandas (PyTables?)HDF5表的写入性能

python - str.contains pandas 返回 'str' 对象没有属性 'contains'

python - 如何将 Django 模型表限制为一行

python - Argparse 中的异常

python - Pygame 转换 : rotate shape on key press

python - 通过比较一行中的列来过滤 Pandas DataFrame

python - 尝试除了递归或 while 循环?