【发布时间】:2020-04-22 03:27:04
【问题描述】:
我有:
df=pd.DataFrame({'text':[['\nThere are a lot of\n things that \nare worthy','\nS\nU\nP\nE\nR'],['\nAnd there is \nlots to see']]})
df
0 [\nThere are a lot of\n things that \nare wort...
1 [\nAnd there is \nlots to see]
我想替换所有的\n,并保持相同的结构。
我试过了:
df['new']=df.text.str.replace('\n','')
text new
0 [\nThere are a lot of\n things that \nare wort... NaN
1 [\nAnd there is \nlots to see] NaN
任何建议
【问题讨论】:
-
为什么是双嵌套列表?如果我尝试使用平面列表,它会起作用