我在数据框中有一列,当前是一个字符串: '2015/4/17下午8:03:45' 我需要根据此列创建其他列 ['dayofweek','dayofmonth']
我找不到快速的解决方案,可以帮助我完成6亿行的操作,请帮助)
答案 0 :(得分:0)
df
numbers time
0 1 2019-01-01
1 2 2019-01-02
2 3 2019-01-03
3 4 2019-01-04
4 5 2019-01-05
5 6 2019-01-06
6 7 2019-01-07
7 8 2019-01-08
8 9 2019-01-09
9 10 2019-01-10
10 11 2019-01-11
11 12 2019-01-12
def day_of_the_week(value):
return value.strftime("%A")
def day_of_the_month(value):
return value.day
df['day_of_the_week'] = df['time'].apply(day_of_the_week)
df['day_of_the_month'] = df['time'].apply(day_of_the_month)
df
numbers time day_of_the_week day_of_the_month
0 1 2019-01-01 Tuesday 1
1 2 2019-01-02 Wednesday 2
2 3 2019-01-03 Thursday 3
3 4 2019-01-04 Friday 4
4 5 2019-01-05 Saturday 5
5 6 2019-01-06 Sunday 6
6 7 2019-01-07 Monday 7
7 8 2019-01-08 Tuesday 8
8 9 2019-01-09 Wednesday 9
9 10 2019-01-10 Thursday 10
10 11 2019-01-11 Friday 11
11 12 2019-01-12 Saturday 12