I have a data frame that looks like this :
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:
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