1

I have two sets of numerical data. One is much larger than the other. The same data from the smaller set applies to the larger set multiple times. For example, where B is the data I need to add to the larger set and C is the number of times each value A is referenced in the large set:

Small set:

A      B      C
123    1      2
456    5      3

Large set:

A      D
123    45
123    58
456    32
456    22
456    89

Desired output:

A      D      B
123    45     1
123    58     1 
456    32     5  
456    22     5
456    89     5

I have only seen questions wherein people want to remove duplicate fields; here it is important I match the value B so that result D can be better understood.

lukalxn
  • 45
  • 1
  • 3

1 Answers1

0

you need, pd.merge

 df=pd.merge(df1,df2,on='A')

 df=df[['A','D','B']]
Pyd
  • 6,017
  • 18
  • 52
  • 109