I have 2 data frame , Need to fetch system_type column based on "Name" column of both dataframe .
I have 500000 rows of df1 as format
Name Timestamp usage AXCS 2022-01-01 5 BGXD 2022-02-01 70 HFSD 2022-03-01 45 AEVC 2022-01-01 25 BHRF 2022-02-01 12
and 550000 rows of df2 as
Name System_Type HFSD Dev BHRF Test BGXD Prod AEVC Prod AXCS Test
I used the following coding
pd.merge(df1, df2, on="Name")
It is taking much time to process , Is there another way/method to process it . Please advise
>Solution :
You can use df2 as a dict mapping:
df1['System_Type'] = df1['Name'].map(df2.set_index('Name')['System_Type'])
print(df1)
# Output
Name Timestamp usage System_Type
0 AXCS 2022-01-01 5 Test
1 BGXD 2022-02-01 70 Prod
2 HFSD 2022-03-01 45 Dev
3 AEVC 2022-01-01 25 Prod
4 BHRF 2022-02-01 12 Test