0

I have two dataframes. First one is like a parent df with many other features and second df contains only the unique values of df['Col1']. Please see below:

df1

Col1
----
C1
C1
C1
C2
C2
C2

df2

Col1  Col2
----  ----
C1    S1
C2    S2

What would be a clean way to combine df2 to df1 as below ? df1

Col1    Col2
----    ----
C1      S1
C1      S1
C1      S1
C2      S2
C2      S2
C2      S2
Geeths
  • 81
  • 7
  • Read this: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.merge.html – Muhammad Hassan Oct 15 '21 at 04:24
  • `df1 = df1.merge(df2, on='Col1')` or `df1['Col2'] = df1['Col1'].map(df2.set_index('Col1')['Col2'])` both options have explanations in the [accepted answer of the linked duplicate](https://stackoverflow.com/a/53645883/15497888) – Henry Ecker Oct 15 '21 at 04:30

0 Answers0