本文介绍了Python Pandas将一系列字符串连接成一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在python pandas中,有一个str值的Series/dataframe列,可以组合成一个长字符串:
In python pandas, there is a Series/dataframe column of str values to combine into one long string:
df = pd.DataFrame({'text' : pd.Series(['Hello', 'world', '!'], index=['a', 'b', 'c'])})
目标:世界你好!"
到目前为止,诸如df['text'].apply(lambda x: ' '.join(x))
之类的方法仅返回Series.
Thus far methods such as df['text'].apply(lambda x: ' '.join(x))
are only returning the Series.
到达目标串联字符串的最佳方法是什么?
What is the best way to get to the goal concatenated string?
推荐答案
您可以直接join
系列上的字符串:
You can join
a string on the series directly:
In [3]:
' '.join(df['text'])
Out[3]:
'Hello world !'
这篇关于Python Pandas将一系列字符串连接成一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!