如何在Jupyter Lab中连接由文本值组成的两列,即字符串?



我有数据存储在Excel工作表中。它有 50 列和 100 行。我已经将数据读入jupyter实验室。我想连接两列,它由文本值组成,即字符串。我尝试使用"pd.concat(['column1','column2']("连接它们。但是,有一个错误指出"类型错误:无法连接类型"的对象;只有系列和数据帧对象有效"。

例如,考虑数据集中存在的以下列, 输入:

column 1
a
b
c
column 2
d
e
f

这是我想要输出的格式。 输出:

New column
ad
be
cf

你能告诉我怎么做吗?

试试这个:

import pandas as pd
#create dataframe
df = pd.DataFrame()
df['col1'] = ['a','b','c']
df['col2'] = ['d','e','f']
#new column
df['new_col'] = df['col1'] + df['col2']

最新更新