My csv/df has 22 cols and I'm looking to make it 4. There are 7 different channel columns and each of these 7 columns have 2 additional columns - value and pct. I want to reshape the data to the below columns:
Date | Channel | Value | Pct
Does it make sense to structure the data this way or should I just rename the columns to include the channel name (ch1_value, ch1_pct, ch2_value, ch2_pct, etc.)?
Eventually I'm looking to plot the data - looking at trends over time per channel. I feel like it'd be easier to do with 4 columns, but maybe I'm wrong. Any suggestions or advice would be helpful. I've played around with pivot_longer
, but just can't make it work.
TIA
Date,Total,Value,Pct,Ch1,Value,Pct,Ch2,Value,Pct,Ch3Value,Pct,Ch4,Value,Pct,ch5,Value,Pct,ch6,Value,Pct
44197,44197,6546,1,44197,1887,0.29,44197,1416,0.22,44197405,0.06,44197,1396,0.21,44197,995,0.15,44197,447,0.07
44198,44198,5099,0.77,44198,1336,0.2,44198,916,0.14,44198444,0.07,44198,225,0.03,44198,320,0.05,44198,1858,0.28
44199,44199,5261,0.81,44199,746,0.11,44199,1065,0.16,4419935,0.01,44199,1088,0.17,44199,1753,0.27,44199,574,0.09
44200,44200,7689,1.17,44200,488,0.07,44200,1578,0.24,442001972,0.3,44200,843,0.13,44200,1649,0.25,44200,1159,0.18
44201,44201,5770,0.89,44201,1174,0.18,44201,1872,0.29,44201280,0.04,44201,409,0.06,44201,623,0.1,44201,1412,0.22