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.

1
  • Look into pandas merge or join. Commented Jul 28, 2018 at 16:41

1 Answer 1

0

you need, pd.merge

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

 df=df[['A','D','B']]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.