作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 concat,它为我提供了“g_spend”中的所有值,但不是“grouped_cw”中的所有值,leads= NaN
t = pd.concat([pd.DataFrame(grouped_cw), g_spend], ignore_index=False)
t.head()
output:
id Campaign_ID_name Month Account campaignid campaign_name cost leads
0 35119190 brand 2019|08 SU 35119190 Brand $59 NaN
使用 join,它给我所有来自“grouped_cw”的值,但不是来自“g_spend”的值,leads= NaN 相反...
t = pd.concat([pd.DataFrame(grouped_cw), g_spend], ignore_index=False)
t.head()
output:
Account Campaign_ID_nameMonthcampaign_namecampaignidcostid leads
1076533154 NaN NaN NaN NaN NaN NaN NaN 40.0
143679198 NaN NaN NaN NaN NaN NaN NaN 58.0
169278078 NaN NaN NaN NaN NaN NaN NaN 13.0
1729099155 NaN NaN NaN NaN NaN NaN NaN 8.0
2016404066 NaN NaN NaN NaN NaN NaN NaN 6.0
Campaign_ID_name Month Account campaignid campaign_name costh leads
0 35119190 35119190 brand 2019|08 SU 35119190 Brand $59 391
g_spend.to_dict()
{'id': {0: 35119190,
1: 64002140,
2: 272351300,
3: 4899110,},
'Campaign_ID_name': {0: 'brand',
1: '-',
2: '-',
3: 'science',
,
'Month': {0: '2019|08',
1: '2019|08',
2: '2019|08',
3: '2019|08',
},
'Account': {0: 'a',
1: 'a',
2: 'b',
3: 'c',
},
'campaignid': {0: 35119190,
1: 64002140,
2: 272351300,
3: 4899110,
},
'campaign_name': {0: 'All_Brand',
1: 'All',
2: 'All_GBHS',
3: 'All_Science',
},
'cost': {0: '$59,399.37 ',
1: '$12,660.37 ',
2: '$5,631.96 ',
}}
grouped_cw.to_dict()
1076533154 引用campaignid40.0 是潜在客户数量
{'leads': {'1076533154': 40.0,
'143679198': 58.0,
'169278078': 13.0,
'1729099155': 8.0,
}}
最佳答案
从to_dict()
命令中可以看出,问题在于g_spend.campaignid
是数字,而grouped_cw.index
是字符串。例如,您可以将 g_spend.campaignid
转换为字符串并合并:
g_spend.campaignid = g_spend.campaignid.astype(str)
g_spend.merge(grouped_cw, left_on='campaignid', right_index=True)
关于python - 如何将系列与数据框合并并保留双方数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58139186/
我是一名优秀的程序员,十分优秀!