Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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
Pandas 如何制作数据帧&x27;s列出要字符串的行?_Pandas_List_Token - Fatal编程技术网

Pandas 如何制作数据帧&x27;s列出要字符串的行?

Pandas 如何制作数据帧&x27;s列出要字符串的行?,pandas,list,token,Pandas,List,Token,我有一个数据帧,每行都是这样的列表: word_count id token 0 6 0 [customer, executive] 1 6 0 [purchase] 2 6 0 [purchase, agent] 3 6 0 [housekeeping] 4 6 0 [night, auditor, &, guest, receptio

我有一个数据帧,每行都是这样的列表:

   word_count   id  token
    0       6   0   [customer, executive]
    1       6   0   [purchase]
    2       6   0   [purchase, agent]
    3       6   0   [housekeeping]
    4       6   0   [night, auditor, &, guest, reception, agent]
  word_count id token
0       6   0   customer executive
1       6   0   purchase
2       6   0   purchase agent
3       6   0   housekeeping
4       6   0   night auditor & guest reception agent
我想将列表转换为如下字符串:

   word_count   id  token
    0       6   0   [customer, executive]
    1       6   0   [purchase]
    2       6   0   [purchase, agent]
    3       6   0   [housekeeping]
    4       6   0   [night, auditor, &, guest, reception, agent]
  word_count id token
0       6   0   customer executive
1       6   0   purchase
2       6   0   purchase agent
3       6   0   housekeeping
4       6   0   night auditor & guest reception agent
我使用了以下方法,但当我看到de.head()时,没有任何变化:

for index, row in de.iterrows():
    row['token']=' '.join(str(e) for e in row['token'])
de.head()

列表理解:

df['token'] = [' '.join(x) for x in df['token']]
应用

df['token'] = df['token'].apply(' '.join)