在 python pandas 中,有一个 str 值的 Series/dataframe 列可以组合成一个长字符串:
df = pd.DataFrame({'text' : pd.Series(['Hello', 'world', '!'], index=['a', 'b', 'c'])})
目标:“你好世界!”
到目前为止,诸如 df['text'].apply(lambda x: ' '.join(x))
之类的方法仅返回系列。
达到目标串联字符串的最佳方法是什么?
原文由 cycle_about 发布,翻译遵循 CC BY-SA 4.0 许可协议
你可以
join
系列上的一个字符串直接: