简体   繁体   English

如何从带有时间戳的数组中获取数据-python中的年,月,日?

[英]How to get from array with Timestamps - years, months, days in python?

How can I get from array with Timestamps - years, months, days? 如何从带有时间戳的数组中获取-年,月,日? I have DataFrame where index is Timestamps and I try this 我有DataFrame的索引是时间戳,我尝试这个

for i in data_frame.index:
    print(datetime.fromtimestamp(i).isoformat())

But I got this error: 但是我得到了这个错误:

print(datetime.fromtimestamp(i).isoformat()) ===>
===> TypeError: an integer is required (got type Timestamp)

first use df['date'] = pd.to_datetime(df['timestap']) to convert to proper format then create new columns for year, month, and day 首先使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM