[英]How to get from array with Timestamps - years, months, days in python?
如何从带有时间戳的数组中获取-年,月,日? 我有DataFrame的索引是时间戳,我尝试这个
for i in data_frame.index:
print(datetime.fromtimestamp(i).isoformat())
但是我得到了这个错误:
print(datetime.fromtimestamp(i).isoformat()) ===>
===> TypeError: an integer is required (got type Timestamp)
首先使用df['date'] = pd.to_datetime(df['timestap'])
转换为正确的格式,然后为年,月和日创建新列
df['year'] = df['date'].dt.year
df['month'] = df['date'].dt.month
df['day'] = df['date'].dt.day
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.