I’ve data like that:
data = {
'nomenclature': ['Display_product', 'Display_product', 'Decorative_textile', 'Decorative_textile', 'Children_clothing', 'Children_clothing', 'Children_textile', 'Children_textile', 'Home_textile', 'Home_textile'],
'city': [1, 2, 1, 2, 1, 2, 1, 2, 1, 2],
'sales_2022': [4249.83, 7676.52, 428591.60, 580723.77, 2384600.57, 1878142.39, 316407.44, 309485.86, 10419592.44, 9594930.55],
'sales_2023': [39376.59, 32938.23, 287329.79, 470398.06, 2663005.41, 2253031.33, 333918.23, 312715.71, 10963845.16, 9967580.97]
}
append is not working for me, I’m getting an error, because it removed from Pandas 2.0.0 and higher.
I know I can create a new column for calculating the percentage, but want to automize that (not creating new rows or columns), but something usual is also good. What about using lambda maybe?
Maybe there is some library close to pivot tables in Excel that can sum a column, add a subtotal, calculate % and display the total, sums and percentages (100, and not sum subtotals)?
append is not working, because it removed from pandas 2.0.0 and higher. I did try concat, but percentage was wrong or summed subtotal to total.
Example of wishing table in Excel
404 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.