Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Compare two dataframes and return common values

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading