[英]Get day of week from UTC_TIME Series in Pandas
當我做
df.dtypes
, 出現這個
utc_time int64
utc_time 的一個例子是:1536444323321
我在這里找到了一個代碼來將 utc_time (epoch) 更改為星期幾
df['Week_Day'] =
datetime.fromtimestamp(df['utc_time']/1000).strftime("%A")
但我收到此錯誤:
TypeError Traceback (most recent call
last)
<ipython-input-124-b3277c232078> in <module>()
2 # df['intage'] = df['utc_time'].astype(int)
3 # df['intage'] = df['utc_time'].dt.days
----> 4 df['Week_Day'] =
datetime.fromtimestamp(df['utc_time']/1000).strftime("%A")
/anaconda3/lib/python3.6/site-packages/pandas/core/series.py in
wrapper(self)
115 return converter(self.iloc[0])
116 raise TypeError("cannot convert the series to "
--> 117 "{0}".format(str(converter)))
118
119 return wrapper
TypeError: cannot convert the series to <class 'int'>
首先,將您的列/系列轉換為日期時間對象。 df['column'] = pd.to_datetime(df['column'])
然后,您有兩個選擇:
選項 1 - 使用.dt
訪問器: df['column'].dt.weekday
將工作日作為整數
選項 2 - 使用熊貓Timestamp
對象: df['column'].apply(pd.Timestamp.weekday)
但我真的推薦選項 1。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.