如何将一个数据框添加到另一个数据框作为新列?

时间:2020-07-14 17:14:52

标签: python pandas dataframe

我有一个41列(和n行)的数据框。我想将另一个数据框添加到主数据框(作为新列)。应该添加到主数据框架的新数据框架可以具有不同的列数,但与主数据框架具有相同的行数。例如:

enter image description here

新数据框应为:

enter image description here

有什么功能吗?

2 个答案:

答案 0 :(得分:0)

您好像标记了熊猫(pd),因此假设您正在使用它,则可以使用:

pd.merge('main data frame', 'second data frame', left_index=True)

答案 1 :(得分:0)

您可以使用pd.concat:

new_df = pd.concat([main_df,second_df], axis=1)