我需要将数据和时间字符串从具有不规则定界符行的数据框中的列中分离出来,即有些带有三个逗号,有些带有四个逗号。
我正在使用Python3,pandas
例:
df['sample field'].head(2)
退货
4457-I need, this, date, Nov 11 2013 12:00AM ,
2359-I need this, date, 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 given the second row has fewer commas. Using:
df['sample field'].str.split(",", expand=True)
将数据扩展到不同的列,并交错显示日期。我在一列中需要日期和时间(甚至只是日期)信息,以便可以在进一步分析中使用日期值。
数据
将df.extract与正则表达式一起使用
IIUC you need
str.extract
with a regular expression.Regex Demo Here