Can someone help me with the below Python/pandas pivoting?
I'm cleaning up a dataset with 95 columns. I want to pivot 10 of those columns into 2 columns within the table.
How do I do this in Python?
Example:
In the below, I want to pivot swimming
, walking
, cycling
and running
into columns activity
& yes_no
.
dummy_df = pd.DataFrame({
"name":["Sally", "Jim", "Bob", "Julie", "Pat"],
"age":[30, 20, 25, 50, 65],
"city":["Edinburgh", "Glasgow", "Aberdeen", "Dundee", "Perth"],
"keep_fit":["Yes", "Yes", "No", "No", "Yes"],
"swimming":["Yes", "No", "No", "No", "No"],
"walking":["No", "Yes", "No", "Yes", "No"],
"cycling":["Yes", "Yes", "Yes", "Yes", "No"],
"running":["No", "No", "Yes", "No", "No"],
})