python - Pandas 数据框中的文本拆分列表

标签 python string pandas list python-3.6

我有由文本列表组成的 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/

相关文章:

python - 函数参数中的裸星号?

python - Scrapy startproject 给出奇怪的错误

c++ - 我怎样才能准确地看到 std::cin 输入缓冲区中的内容?

python - 遍历字符串的行

python - 字典的嵌套列表与将字典的嵌套列表放入Pandas数据框中

python - 如何将文本文件加载到 pandas 数据框中?

python - 如何执行 python 脚本并保持打开的 shell 以便在 VIM 中进行进一步测试

python - 按一天中的时间分组数据

c# - 在 C# 中的字符串中找到 {0} 是什么意思?

python - 根据列值合并数据框