我有两个数据帧,我想组合成一个新的DF。
df1: Category Locale Provider Traffic Weeknumber
Clickout AT A 1200 1
Clickout DE B 3400 2
Popunder COM A 50 1
Popunder COM B 50 2
df2: Device Locale Provider Weeknumber Clickout Popunder
Mobile AT A 1 200 300
Desktop DE A 2 2000 1400
Mobile COM B 1 250 500
Desktop COM B 2 100 850
新数据框应该是什么样的:
df3: Category Locale Provider Traffic Weeknumber Mobile Desktop
Clickout AT A 1200 1 500 700
Clickout DE A 3400 2 2000 1400
Popunder COM B 750 1 250 500
Popunder COM B 950 2 100 850
我想有两个步骤,df2将列clickout和popunder切换成行,并将设备类型更改为列。然后根据Locale,Provider和Weeknumber将其与df1合并。
这就是excel公式的样子(如果它有帮助的话)
{=INDEX('Sheet_2'!A:G,MATCH(1,('Sheet_2'!A:A=
[@Locale])*('Sheet_2'!C:C=[@provider])*('Sheet_2'!E:E=[@Weeknumber])*('Sheet_2'!B:B=Sheet_1_crosstab!T$1),0),MATCH([@[source_aggregated]],'Sheet_2'!$A$1:$G$1,0))}
任何帮助都会很棒,谢谢!