当我做
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'>
首先,将列/ Series转换为datetime对象。 df['column'] = pd.to_datetime(df['column'])
然后,您有两个选择:
.dt
访问器:df['column'].dt.weekday
为工作日提供整数Timestamp
对象:df['column'].apply(pd.Timestamp.weekday)
但我真的推荐选项1。