[英]How to split sentence into words, each in a new row after seeing a letter like "RN" in the sentence
I have a dataframe, that sometimes contains RN in the sentence.我有一个数据框,有时在句子中包含 RN。
I want to split the sentence into words and each in a new row whenever RN appears in any sentence.每当 RN 出现在任何句子中时,我想将句子拆分为单词,并将每个单词放在一个新行中。
For example:例如:
Before:前:
After :后 :
I only used:我只用过:
df=df.assign(text=df['Default'].str.split('𝑅N')).explode('text')
I solved it, the issue is that "RN" was not really recognized by python because it was bold with hidden signs and not really clear, so I replaced to ,R,N then I applied:我解决了,问题是“RN”并没有真正被python识别,因为它带有隐藏符号并且不是很清楚,所以我替换为,R,N然后我申请了:
df=df.assign(text=df['Deafault'].str.split(',R,N')).explode('text')
and it works!它有效!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.