简体   繁体   中英

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

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['year'] = df['date'].dt.year
df['month'] = df['date'].dt.month
df['day'] = df['date'].dt.day

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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