Home > front end >  How to merge three dataframes with same columns, different rows containing strings, float, etc?
How to merge three dataframes with same columns, different rows containing strings, float, etc?

Time:05-04

I have three dataframes (df1,df2,df3) that share the same columns with the following types:

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 (i.e. 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:

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

CodePudding user response:

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. It should be:

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

rather than:

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