我在数据框中有一列聊天对话,每个单元格中的一般格式是:'姓名代理 : 对话'我想创建一个仅包含对话部分的新列。我使用以下代码做到了这一点:filtered_transcript_text['msgText'].str.split(':', expand = True)但是,此函数会为每次出现而不是仅为第一次创建拆分。有没有办法只在实例第一次出现时使用split函数?我知道我可以合并其他创建的列,但这对我来说似乎很狡猾。
2 回答

手掌心
TA贡献1942条经验 获得超3个赞
尝试添加 n=1
filtered_transcript_text['msgText'].str.split(':', expand = True,n=1)

慕的地10843
TA贡献1785条经验 获得超8个赞
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.split.html
.str.split(pat=":", n=1, expand=True)
添加回答
举报
0/150
提交
取消