我有两个数据框,会话 1 和会话 2,我想在字段 'ga:dimension1' 上加入它们。sessions1.info()<class 'pandas.core.frame.DataFrame'>RangeIndex: 15775 entries, 0 to 15774Data columns (total 9 columns):ga:dimension1 15775 non-null objectga:date 15775 non-null objectga:deviceCategory 15775 non-null objectga:landingPagePath 15775 non-null objectga:userType 15775 non-null objectga:operatingSystem 15775 non-null objectga:operatingSystemVersion 15775 non-null objectga:sessions 15775 non-null int64ga:bounces 15775 non-null int64dtypes: int64(2), object(7)memory usage: 1.1+ MBsessions2.info()<class 'pandas.core.frame.DataFrame'>RangeIndex: 15774 entries, 0 to 15773Data columns (total 9 columns):ga:dimension1 15774 non-null objectga:source 15774 non-null objectga:medium 15774 non-null objectga:campaign 15774 non-null objectga:adContent 15774 non-null objectga:keyword 15774 non-null objectga:channelGrouping 15774 non-null objectga:sessions 15774 non-null int64ga:bounces 15774 non-null int64dtypes: int64(2), object(7)memory usage: 1.1+ MB看看前几行,它们至少看起来是一样的:sessions1.head() ga:dimension1 ga:date ... ga:sessions ga:bounces0 1567331564026.evxjzuot 20190901 ... 1 11 1567331572999.vtnsczsj 20190901 ... 1 12 1567331693070.fkdbmcj6 20190901 ... 1 13 1567335919816.ctz12xcl 20190901 ... 1 04 1567345181556.b3yowmbh 20190901 ... 1 1但是,当我尝试这个时:sessions_combined = sessions1.join(sessions2, on = 'ga:dimension1', how = 'left')我收到一条错误消息:ValueError:您正在尝试合并 object 和 int64 列。如果你想继续,你应该使用 pd.concat为什么会这样,我应该如何将两个数据框连接在一起?
1 回答
郎朗坤
TA贡献1921条经验 获得超9个赞
利用merge
sessions_combined = sessions1.merge(sessions2, on = 'ga:dimension1', how = 'left')
添加回答
举报
0/150
提交
取消