[英]Get day of week from UTC_TIME Series in Pandas
When I do当我做
df.dtypes
, appears this , 出现这个
utc_time int64
one example of utc_time is: 1536444323321 utc_time 的一个例子是:1536444323321
I found a code here to change utc_time (epoch) to day of week我在这里找到了一个代码来将 utc_time (epoch) 更改为星期几
df['Week_Day'] =
datetime.fromtimestamp(df['utc_time']/1000).strftime("%A")
But i receive this error:但我收到此错误:
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'>
First, convert your column/Series to a datetime object.首先,将您的列/系列转换为日期时间对象。 df['column'] = pd.to_datetime(df['column'])
Then, you have two options:然后,您有两个选择:
Option 1 - use the .dt
accessor: df['column'].dt.weekday
gives you the weekdays as integers选项 1 - 使用.dt
访问器: df['column'].dt.weekday
将工作日作为整数
Option 2 - use the pandas Timestamp
object: df['column'].apply(pd.Timestamp.weekday)
选项 2 - 使用熊猫Timestamp
对象: df['column'].apply(pd.Timestamp.weekday)
But I really recommend option 1.但我真的推荐选项 1。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.