我试图在数据帧中为时间戳HOUR,DAY,MONTH和DatetimeIndex的值构建3个单独的列。在
因为我的数据集是从CSV文件中读取的,所以我对无法复制的数据进行了赋值。在
boilerDf = pd.read_csv('C:\\Users\\Python Scripts\\Deltadata.csv', index_col='Date', parse_dates=True)
print(boilerDf.info())
这将返回:
^{pr2}$我可以看到pandas.pydata.org除了我想创建单独的数据帧(列)之外,我正在尝试的是3种方法:
DatetimeIndex.month
DatetimeIndex.day
DatetimeIndex.hour
下面的代码不适用于为日期时间索引的小时添加单独的数据帧列。。。有什么想法吗?在
boilerDf['Hour'] = boilerDf.DatetimeIndex.hour
谨致问候
我在Github上也上传了数据: bbartling/Data on Github
我最初建议。索引.strftime()为这个答案。然而,Henry还发现了jezrael的Pandas time series data Index from a string to float,它返回integer类型的列。因此,我在这里包含了后者的扩展版本。当使用这两种不同的方法时,输出有一点不同。在
相关问题 更多 >
编程相关推荐