如何将系列合并为一个值?我试过pd.concat()
。
dict = {"Cities": ["Chicago", "Hong Kong", "London"], "People": ["John", "Mike", "Sue"]}
df = pd.Dataframe.from_dict(dict)
Cities People
0 Chicago John
1 Hong Kong Mike
2 London Sue
*所需的输出:*
"John Mike Sue"
答案 0 :(得分:4)
除' '.join(df.People)
Series.str.cat
In [96]: df.People.str.cat(sep=' ')
Out[96]: 'John Mike Sue'
答案 1 :(得分:1)
我相信' '.join(series)
应该这样做
答案 2 :(得分:0)
试试这个:
# Cannot be named dict, as dict is a type.
dictionary = {"Cities": ["Chicago", "Hong Kong", "London"], "People": ["John", "Mike", "Sue"]}
print(' '.join(dictionary['People'])
您不必输入第一行,因为它是注释。