我需要从具有不规则定界符行的数据框中的一列中删除日期和时间字符串,即有些带有三个逗号,有些带有四个逗号。
我正在使用Python3,pandas
例:
df['sample field'].head(2)
退货
4457-I only, need, this, Nov 11 2013 12:00AM ,
2359-I only need, this, Apr 11 2013 12:00AM ,
I am trying to figure out how to strip the date and time values: 'Nov 11 2013 12:00AM'
, and 'Apr 11 2013 12:00AM'
off the back of these two records in a column into a new column "I only need this" above, without the date on the back-end.
要进行相反的操作,我使用了以下内容:
df3_1['Date'] = df3_1['Course ID'].str.extract('([A-Za-z]+\s+\d+\s+\d+\s+\d+:[0-9A-Z]+(?=\s+\,+))')
这在删除日期时效果非常好,但是我现在正试图找出如何保留不带日期的文本。
假设您已经有日期列