【发布时间】:2019-05-25 07:08:09
【问题描述】:
我是一个Pandas DataFrame如下:
df = pd.DataFrame({
'id': [1,2 ,3],
'txt1': ['Hello there1', 'Hello there2', 'Hello there3'],
'txt2': ['Hello there4', 'Hello there5', 'Hello there6'],
'txt3': ['Hello there7', 'Hello there8', 'Hello there9']
})
df
id txt1 txt2 txt3
1 Hello there1 Hello there4 Hello there7
2 Hello there2 Hello there5 Hello there8
3 Hello there3 Hello there6 Hello there9
我想连接列txt1、txt2 和txt3。到目前为止,我能够实现如下:
df['alltext'] = df['txt1'] + df['txt2'] + df['txt3']
df
id txt1 txt2 txt3 alltext
1 Hello there1 Hello there4 Hello there7 Hello there1Hello there4Hello there7
2 Hello there2 Hello there5 Hello there8 Hello there2Hello there5Hello there8
3 Hello there3 Hello there6 Hello there9 Hello there3Hello there6Hello there9
但是如何在 Pandas 中连接时在两列字符串之间引入 空格 字符?
我刚刚开始学习 Pandas。
【问题讨论】: