0

I have the following situation. I have Table A. I want to write a python code based on common fields Column 1 and Column C to be output into a new Table X. The code must take the first value from Column 1 and go through all the rows in column C. Every time there is a match it must append the Table 1 row to that related row in table 2 into the new table X. This is a one is to many join.

Table 1:
Column1 Column 2 Column 3
10      f         str
20      a         rd
30      f         ave
60      f         str
90      a         rd
100     f         ave


Table 2:
Columna Columnb Column c
  str    new         20
  str    old         10
  ave    new         20
  str    new         30
  str    old         10
  ave    new         40

Table x:

Column1 Column 2 Column 3  Columna  Columnb Columnc
10      f         str      str    old         10
10      f         str      str    old         10
20      a         rd       str    new         20
20      a         rd       ave    new         20
30      f         ave      str    new         30
Mayank Porwal
  • 33,470
  • 8
  • 37
  • 58
Shrek
  • 3
  • 1
  • 6
  • 1
    Use `df1.merge(df2, left_on='Column1', right_on='Columnc')` – Mayank Porwal Mar 04 '21 at 07:43
  • Hi. Im sorry im verry new to programming and pandas. Should i do something like 'import pandas as pd' How would i define d1 and d2, if i have to? I read the associated post and am still confused – Shrek Mar 06 '21 at 13:45

0 Answers0