I have two DataFrames:
df1
PRA_Kod;WorkerId
1049;9024
0014;60260
0608;10506
20270/9;20270
9511;64473
0639;60264
0767;10509
.. .. .. . .
df2
WorkerId;Day;Time;W
1049;11;u.wyp;WE
1049;14;u.wyp;WE
64454;11;u.wyp;WE
0014;15;u.wyp;WE
64471;12;u.wyp;WE
64471;13;u.wyp;WE
0639;06;u.wyp;WE
0639;01;u.wyp;WE
0639;02;u.wyp;WE
0639;03;u.wyp;WE
64465;04;u.wyp;WE
64465;05;u.wyp;WE
... ... .. .
I need to change the value in the column df2['WorkerId'] to the value df1['WorkerId'] if df2['WorkerId'] appears in df1['PRA_Kod'].
A note: PRA_Kod value "20270/9" is no typo. These tables result from combining data from different tables. Some users happen to have different indexes accross different tables.
Desired output:
df_result
WorkerId;Day;Time;W
9024;11;u.wyp;WE
9024;14;u.wyp;WE
64454;11;u.wyp;WE
60260;15;u.wyp;WE
64471;12;u.wyp;WE
64471;13;u.wyp;WE
60264;06;u.wyp;WE
60264;01;u.wyp;WE
60264;02;u.wyp;WE
60264;03;u.wyp;WE
64465;04;u.wyp;WE
64465;05;u.wyp;WE
... ... .. .
How can this be done?
My attempt below results raises ValueError: Can only compare identically-labeled Series objects.
df_result.loc[ df2['WorkerId'].eq == df1['PRA_Kod'].eq,
df2['WorkerId'] ] = df1['WorkerId']
querycan do this. statology.org/…