Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将dataframe列转换为字符串列表_Python_Pandas_Dataframe - Fatal编程技术网

Python 将dataframe列转换为字符串列表

Python 将dataframe列转换为字符串列表,python,pandas,dataframe,Python,Pandas,Dataframe,从dataframe列中提取字符串列表,如我的代码所示: d = {'text': ["Hello", "How are you","From","Liban"]} df = pd.DataFrame(data=d) df 我的名单上会有 List_text = ["Hello","How are you","From","Liban"]. 谢谢使用: 您可以迭代目标列中的元素,并将想要的元素添加到空列表中 d = {'text': ["Hello", "How are you","

从dataframe列中提取字符串列表,如我的代码所示:

d = {'text': ["Hello", "How are you","From","Liban"]}
df = pd.DataFrame(data=d)
df
我的名单上会有

    List_text = ["Hello","How are you","From","Liban"].
谢谢

使用:


您可以迭代目标列中的元素,并将想要的元素添加到空列表中

d = {'text': ["Hello", "How are you","From","Liban"]}
df = pd.DataFrame(d)
rows,columns=df.shape

list_text=[] #your empty list 
for index in range(rows): #iteration over the dataframe
    list_text.append(df.iat[index,0])

print(list_text)

嘿@Erfan我必须对这两个进行速度测试^^^当然,继续。也很奇怪:)同样的东西831ms与823ms的+/-30ms,所以这可能是一个CPU性能,不知道,但这几乎是相同的速度,我会投票给你;)虽然此命令可以回答该问题,但提供有关此代码为什么和/或如何回答该问题的其他上下文可以提高其长期价值。我将添加描述
d = {'text': ["Hello", "How are you","From","Liban"]}
df = pd.DataFrame(d)
rows,columns=df.shape

list_text=[] #your empty list 
for index in range(rows): #iteration over the dataframe
    list_text.append(df.iat[index,0])

print(list_text)