且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将数据从合并的单元格拆分为Python数据框同一行中的其他单元格?

更新时间:2023-02-04 19:46:08

您可以使用 str.split 方法将字符串拆分为单词。

You can use the str.split method to split the string into "words".

df['list_of_words'] = dftopdata['Date'].str.split()

如果有一种模式可以从中拆分 Professional Description 部分 list_of_words -您可以使用它。例如,如果 list_of_words 的前两个单词组成专业人员的名称,那么您可以-

If there is a pattern to split the Professional and Description parts from this list_of_words - you can use it. For instance, if the first 2 words of list_of_words make up the name of the professional then you can do -

df['Professional'] = df.apply(lambda x: ' '.join(x['list_of_words'][:2]), axis=1)
df['Description'] = df.apply(lambda x: ' '.join(x['list_of_words'][2:]), axis=1)