【发布时间】:2020-08-05 12:03:38
【问题描述】:
我正在使用 pandas 将 csv 文件加载到数据框中。
我的数据框看起来像这样:
col1 col2 col3
1 4 1
2 5 2
3 6 3
我希望将 2 列追加到一个新列中:
col1 col2 col3 col4
1 4 1 1
2 5 2 2
3 6 3 3
4
5
6
col4 需要通过将 col1 和 col2 的内容附加在一起来创建。
如何在 pandas/python 中做到这一点?
编辑
df = df.reset_index(drop=True)
s = df['full_name'].append(df['alt_name'], ignore_index=True).rename('combined_names')
df = df.join(s, how='outer')
df = df.reset_index(drop=True)
s = df['full_address'].append(df['alt_add'], ignore_index=True).rename('combined_address')
df = df.join(s, how='outer')
【问题讨论】:
-
您能向我们展示一下您在代码方面的起步吗?
-
解决方案有问题?
标签: python pandas dataframe data-science