数据集被分割成更小的部分:
df_wiki.Release.head(50)
Title
100 Days My Prince September 10 – October 30, 2018
A Gentleman's Dignity 26 May –12 August 2012
A Model Family 2022
Adamas July 27, 2022
Alchemy of Souls June 18, 2022 –presentJune 18, 2022 –present
Alice none
All About Eve April 26 – July 6, 2000
Name: Release, dtype: object
我已经尝试将其转换为字符串类型,链接的lstrip, strip,替换和删除所有空白,但破折号不会消失。
df_wiki.Release.astype(str).str.replace(' ','').str.split('-', expand=True)[0].head(50)
df_wiki.Release.str.lstrip().str.split('-', expand=True).head(50)
它最终看起来像这样:
100 Days My Prince September10 –October30,2018
A Gentleman's Dignity 26May –12August2012
A Model Family 2022
Adamas July27,2022
Alchemy of Souls June18,2022 –presentJune18,2022–present
Alice none
All About Eve April26–July6,2000
Name: Release, dtype: object
我想让它看起来像使用分割命令:
df_wiki[['Start', 'End']] = df_wiki['Release'].str.split('-', expand=True)
df_wiki.drop('Release', axis=1, inplace=True)
Title START END
100 Days My Prince September 10, 2018 October 30, 2018
A Gentleman's Dignity May 26, 2012 August 12, 2012
A Model Family none 2022
Adamas none July 27, 2022
Alchemy of Souls June 18, 2022 June 20, 2022
Alice none none
All About Eve April 26, 2000 July 6, 2000
Name: Release, dtype: object
再次感谢您的帮助。
在示例中
'–' != '-'
Out[840]: True
将sep改为右1
df_wiki[['Start', 'End']] = df_wiki['Release'].str.split('–', expand=True)