[英]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.