Python Program for Column to Row Transpose using Pandas
Given an Input File, having columns Dept and Name, perform an operation to convert the column values to rows. Name contains pipe separated values that belong to a particular department identified by the column Dept.
Attached Dataset: emp_data
Input: dept, name 10, Vivek|John 20, Ritika|Shubham|Nitin 30, Vishakha|Ankit Output: dept, name 10, Vivek 10, John 20, Ritika 20, Shubham 20, Nitin 30, Vishakha 30, Ankit
Method 1: Pythonic Way
Note: Shortcoming of above method is when there are more than 3 names separated by |
Method 2: Exploring Pandas
Method 3: The Pandas way: explode()
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course