Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12231

Avoiding Merge In Pandas

$
0
0

I have a data frame that looks like this :

enter image description here

I want to group the data frame by #PROD and #CURRENCY and replace TP with the contents of the Offshore data in the Loc column Without creating two data frames and joining them.

The final output will look something like:

enter image description here

I was able to create the output by splitting the data frame into two (Onshore and Offshore ) and then creating a join on #PROD and #CURRENCY. However, I was wondering if there is a cleaner way to do this ?

The Code for the Dataframe is :

import pandas as pddata=[['Offshore','NY','A','USD','ABC_USD'],['Onshore','BH','A','USD',''],                  ['Onshore','AE','A','USD',''],\     ['Offshore','NY','A','GBP','GBP_ABC'],['Onshore','BH','A','GBP',''],                           ['Onshore','AE','A','GBP',''],\     ['Onshore','BH','A','EUR',''],['Onshore','AE','A','EUR','']]df = pd.DataFrame(data, columns=['Loc', 'Country','#PROD','#CURRENCY','TP'])df

Viewing all articles
Browse latest Browse all 12231

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>