Skip to content
Advertisement

How to replace one column value with many in pandas dataframe

Input dataframe

JavaScript

How to replace value in column Geo so that there is a one to many mapping and Shipment values are duplicated?

Output df

JavaScript

Advertisement

Answer

Use DataFrame by cosntructor, then outer join by DataFrame.merge and reassign column Geo by DataFrame.pop:

JavaScript

JavaScript

Solution with new data:

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