简体   繁体   English

如何合并具有相同列、包含字符串、浮点数等的不同行的三个数据框?

[英]How to merge three dataframes with same columns, different rows containing strings, float, etc?

I have three dataframes (df1,df2,df3) that share the same columns with the following types:我有三个数据帧(df1、df2、df3),它们共享具有以下类型的相同列:

Unnamed: 0                 int64
_id                       object
dataNotificacao           object
cnes                      object
ocupacaoSuspeitoCli      float64
ocupacaoSuspeitoUti      float64
ocupacaoConfirmadoCli    float64
ocupacaoConfirmadoUti    float64
ocupacaoCovidUti         float64
ocupacaoCovidCli         float64
ocupacaoHospitalarUti    float64
ocupacaoHospitalarCli    float64
saidaSuspeitaObitos      float64
saidaSuspeitaAltas       float64
saidaConfirmadaObitos    float64
saidaConfirmadaAltas     float64
origem                    object
_p_usuario                object
estadoNotificacao         object
municipioNotificacao      object
estado                    object
municipio                 object
excluido                    bool
validado                    bool
_created_at               object
_updated_at               object

No rows are fully equal (ie there are no duplicates).没有行是完全相等的(即没有重复)。 The three data frames are for three different time periods.三个数据帧用于三个不同的时间段。 How can I merge all my rows with the same columns?如何将所有行与相同的列合并?

I have tried using the pd.concat() formula but I get the following error:我尝试使用 pd.concat() 公式,但出现以下错误:

TypeError: cannot concatenate object of type '<class 'str'>'; only Series and DataFrame objs are valid

You didn't post the code you're running, but it sounds like you're passing the dataframe variable names into pd.concat as strings.您没有发布正在运行的代码,但听起来您正在将 dataframe 变量名称作为字符串传递到 pd.concat 中。 It should be:它应该是:

pd.concat([df1, df2, df3])

rather than:而不是:

pd.concat(['df1','df2','df3'])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 熊猫:基于列值合并2个数据框; 对于包含相同列值的多个行,请将其附加到不同的列 - Pandas: Merge 2 dataframes based on a column values; for mulitple rows containing same column value, append those to different columns 如何合并两个具有不同列名但行数相同的数据框? - How to merge two dataframes with different column names but same number of rows? 如何在包含重复项的多个列上合并 2 个数据框 - How to merge 2 dataframes on multiple columns containing duplicates 比较具有相同列和不同行的两个数据框 - Comparing two dataframes with same columns and different rows 如何合并 3 个 Pandas DataFrames,其中包含除几列之外的相同数据? - How can I merge 3 Pandas DataFrames containing the same data except for a few columns? 合并具有不同列名和不同行数的多个数据框 - merge multiple dataframes with different columns names and different rows number 在 Python 中合并三个不同的数据框 - Merge three different dataframes in Python 如何合并来自不同数据框的一些列 - how to merge some columns from different dataframes 如何合并具有不同列的2个布尔数据框? - how to merge 2 boolean dataframes with different columns? 对具有相同列,不同顺序的三个按组分组结果数据帧执行联合 - Performing union on three Group by Resultant dataframes with same columns, different order
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM