Skip to content
Advertisement

Pandas Set Index Based On Column Value

I’m new to pandas, I have a Dataframe read from excel file, like this screenshot below where Products is the header and Google and Meta is the group (index)

JavaScript

enter image description here

Using pandas I would like the dataframe to be like this

enter image description here

Thank You

Advertisement

Answer

Using pd.assign and np.where

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement