我有由文本列表组成的 pandas 数据框,我想将文本拆分为 ,
df['c1']=['this is text one','this is text two','this is text three']
我试过了
new = df["c1"].str.split(",", n = 1, expand = True)
但它是我 Nan 的新变量
预期输出
c1='this is text one'
c1='this is text two'
c1='this is text three'
其他输出是可以的,只要它拆分列表中的文本。感谢您的帮助 完整代码
import pandas as pd
data={"C1":[["this is text one","this is text two","this is text three"]]}
df=pd.DataFrame(data)
df.head()
最佳答案
你不需要 pandas 来拆分你可以使用 for 循环的数组
这就是你想要的
for i in df['C1']:
for each in i:
print(each) #outputs each element in the array
关于python - Pandas 数据框中的文本拆分列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56098022/