2

I have two dataframe (data and priceMapping)

Data:

       Global id   Price
0   AR.1852218.1     
1   AR.1852223.1     0,6
2   AR.1852251.1    0,56
3   AR.1852254.1    
4   AR.1852257.1    0,25
5   AR.1852386.1    0,33
6   AR.1852549.1    

priceMapping:

        G.ID       Price
0   AR.1852218.1     0,1
1   AR.1852254.1    0,25
2   AR.1852549.1    0,33

I would like to fill the price that is in the priceMapping dataframe based on the criteria Global id=G.ID.

Thanks in advance for your help.

Laurent

1 Answer 1

2

Use Series.map by Series created by priceMapping and then replace not matched values to original by Series.fillna, because not matched values create missing values:

s = priceMapping.set_index('G.ID')['Price']
Data['Price'] = Data['Global id'].map(s).fillna(Data['Price'])
print (Data)
      Global id Price
0  AR.1852218.1   0,1
1  AR.1852223.1   0,6
2  AR.1852251.1  0,56
3  AR.1852254.1  0,25
4  AR.1852257.1  0,25
5  AR.1852386.1  0,33
6  AR.1852549.1  0,33

Another idea is use Series.replace:

s = priceMapping.set_index('G.ID')['Price']
Data['Price'] = Data['Global id'].replace(s)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.