[英]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.