Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.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_Python 3.x_Pandas_List - Fatal编程技术网

Python 如何将dataframe列转换为列表,并将列表中的值用双引号括起来

Python 如何将dataframe列转换为列表,并将列表中的值用双引号括起来,python,python-3.x,pandas,list,Python,Python 3.x,Pandas,List,我在dataframe中有一个列表列,如下所述 df=pd.DataFrame({'a':["a,b,c"]}) df: ['a,b,c'] 但是我希望输出是这种格式的[“a”,“b”,“c”]。 有人能帮我翻译一下代码吗。以下代码将生成所需的输出- df.a.apply(lambda x: str(x.split(','))) df['a']=[str(i.split(',')) for i in df.a] 输出- ['a', 'b', 'c'] 我们使用逗号分割,然后将每个元素转

我在dataframe中有一个列表列,如下所述

 df=pd.DataFrame({'a':["a,b,c"]})
df:

['a,b,c']

但是我希望输出是这种格式的[“a”,“b”,“c”]。
有人能帮我翻译一下代码吗。

以下代码将生成所需的输出-

df.a.apply(lambda x: str(x.split(',')))
df['a']=[str(i.split(',')) for i in df.a]
输出-

['a', 'b', 'c']
我们使用逗号分割,然后将每个元素转换为字符串

编辑1:

这段代码也可用于获得相同的输出-

df.a.apply(lambda x: str(x.split(',')))
df['a']=[str(i.split(',')) for i in df.a]

df.a.str.split(',')
?我不想拆分列表中的值,而是需要将列表中的每个元素都用双引号括起来。如何
[I.split(',')表示df.a中的I]
@DppriyaReddy,双引号还包含在单个字符串中?像
“a”、“b”、“c”
?试试这个-df.a.apply(lambda x:str(x.split('),'))嗨,你能告诉我如何用双引号代替单引号吗