I'm trying to code in Python after a hiatus of 4 years and facing difficulties in implementing my ideas. I have 2 large excel sheets consisting of more than 12k x 70 values, both have the same number of columns and column names. I've created a primary key for both the dataframes and now I want to compare values from the primary key of one sheet to primary key of another and when there's a match I want to replace certain values(not all) from the old sheet to the new.
eg
df1:
A B C D E F
1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18
DF2:
A B C D E F
19 20 21 22 23 6
25 26 27 28 29 12
31 32 33 34 35 19
当手术完成后,我需要它看起来像这样 DF1:
A B C D E F
1 2 21 22 23 6
7 8 27 28 29 12
13 14 15 16 17 18
列F是主键
我try 了下面的方法,但输出结果非常奇怪
for i in df2['F']:
for j in df1['F']:
if i==j:
df1['D'] = df2['D'].astype(str)
df1['E'] = df2['E'].astype(str)
df1['C'] = df2['C'].astype(str)