2

I have two CSV files. One is called 'master_registry.csv' and another one is 'master_reference.csv'. Both of these CSV files have a column called 'Master_Id'. I have filtered some values including 'Master_Id' from the 'master_registery.csv' and created new data frame called 'df' and also I have filtered some values including 'Master_Id' from 'master_reference.csv' and created a new data frame called 'df2'. So both of these data frames have 'Master_Id' column. Now I want to create new data frame by combining both 'df' and 'df2' data frames. Can anyone help me do this?

    # reading CSV from the directory
    master_registry = pd.read_csv('application/master_registry.csv')
    master_reference = pd.read_csv('application/master_registry.csv')

    # filtering some selected columns form the csv
    df = master_registry .filter(items=['Master_ID', 'Provider First Name', 'Provider Last Name (Legal Name)', 'Provider Credential Text', 'Provider Gender Code','Provider License Number State Code_1',
                    'Provider Business Practice Location Address City Name'])

    df2 = master_reference .filter(items=['Master_ID', 'Client_Reference_ID'])
Mr. T
  • 11,960
  • 10
  • 32
  • 54
Theesh
  • 187
  • 1
  • 18

2 Answers2

1

It seems to me that you want to merge the two data frames by 'Master ID'. You can have a look at this link.

I think this should solve your problem: pd.merge(df, df2, on='Master_ID')

naive
  • 367
  • 1
  • 3
  • 9
  • Link-only answers are discouraged. See https://stackoverflow.com/help/how-to-answer. Quote the relevant part of the link because links can go invalid over time. – Mark Tolonen Jun 15 '18 at 05:50
  • @MarkTolonen I have edited the answer and have tried to make it useful. Thanks! – naive Jun 16 '18 at 04:52
1

Use the join method. Usage below -

df.set_index('Master_ID').join(df2.set_index('Master_ID'))
Sahil Agarwal
  • 555
  • 3
  • 12