我有pandas dataframe
,其列的值如下:
Day 1, Week 1, Year 1990
Day 2, Week 1, Year 1990
Day 3, Week 1, Year 1990
Day 4, Week 1, Year 1990
我想分别提取一天,一周和一年。请注意这里和那里的额外空间!我可以使用lstrip()
和rstrip()
在开头和结尾删除多余的空格。但是,无法处理字符串之间的空间。有什么方法可以有效地提取星期几和年份。
预期产量
df['Day'] = 1, df['Week'] = 1, df['Year'] = 1990
df['Day'] = 2, df['Week'] = 1, df['Year'] = 1990
df['Day'] = 3, df['Week'] = 1, df['Year'] = 1990
df['Day'] = 4, df['Week'] = 1, df['Year'] = 1990