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

如何从带有时间戳的数组中获取python中的年、月、日?,python,datetime,time,timestamp,Python,Datetime,Time,Timestamp,如何从带有时间戳的数组中获取时间戳-年、月、日? 我有一个数据帧,索引是时间戳,我试着这样做 for i in data_frame.index: print(datetime.fromtimestamp(i).isoformat()) 但我有一个错误: print(datetime.fromtimestamp(i).isoformat()) ===> ===> TypeError: an integer is required (got type Timestamp)

如何从带有时间戳的数组中获取时间戳-年、月、日? 我有一个数据帧,索引是时间戳,我试着这样做

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