pivot-table

How to make a pivot table from a dataframe that groups by year and count my data

How to make a pivot table from a dataframe that groups by year and count my data Question: Hello people i have a question, i have a dataframe with different products and dates, something like this: product date A 01-01-2016 A 01-02-2016 B 23-04-2016 B 22-02-2016 A 02-12-2017 A 13-11-2017 B 12-12-2017 What i want …

Total answers: 1

Python one pivot table for different type of aggregation

Python one pivot table for different type of aggregation Question: I have an input df like: category name cost cost2 Tier1 Tina 10 5 Tier1 Jessy 20 15 Tier1 Tina 30 10 Need output: category count distinct name sum of cost avg of cost2 Tier1 2 60 10 It is similar to SQL: select category, …

Total answers: 1

Pandas pivot or pivot table?

Pandas pivot or pivot table? Question: I am trying to take an excel data frame with the following format: DOW Location 7/30/2022 8/6/2022 8/13/2022 8/20/2022 Volumes Saturday North 33 32 29 24 Volumes Saturday South 34 17 30 28 Volumes Sunday North 40 57 25 28 Volumes Sunday South 47 38 32 45 ACT Saturday …

Total answers: 1

Python (Pandas) pivot datframe, some sums keeping the order

Python (Pandas) pivot datframe, some sums keeping the order Question: I’m trying to get from a to b. I got a Pandas data frame similar to the a below. data={‘col1’:[‘N1′,’N1′,’N2′,’N2’, ‘N2′,’N3’], ‘col2’:[‘DE’,’NO’,’DE’,’NO’, ‘IT’,’DE’], ‘col3’:[7, 5, 4, 1, 2, 8], ‘col3_sum’:[12, 12, 7, 7, 7, 8], ‘col4’:[0.6, 0.2, 0.7, 0.1, 0.2, 0.6], ‘col4_sum’:[0.8, 0.8, 1.0, 1.0, …

Total answers: 2

Drop column and line in pivot table

Drop column and line in pivot table Question: Having a pivot table as below: is it possible that i can drop a column and row? I need to drop the column and line ‘C’? Is it possible that i can drop the None value? None is a <class ‘NoneType’> Asked By: Mathew John || Source …

Total answers: 1

Display Mean of Crosstab

Display Mean of Crosstab Question: I have a dataframe ‘df’. I want to display all rows of the ‘Percentage of 1/Yes’ column that are greater than the average of the column. My code displays whether it is True/False, but I want to display the actual value for the True rows and not display the False …

Total answers: 1

Similar to pivot table in Python

Similar to pivot table in Python Question: Here is a dataframe data_1. data_1=pd.DataFrame({‘id’:[‘1′,’1′,’1′,’1′,’1′,’2′,’2′,’2′,’2′,’2’], ‘date’:[‘20220325′,’20220325′,’20220325′,’20220327′,’20220327′,’20220705′,’20220705′,’20220706′,’20220706′,’20220706’], ‘base’:["wt","bmi","p","wt","wt","bmi","bmi","wt","p","bmi"], ‘value’:[’75’,’21’,’25’,’76’,’77’,’19’,’18’,’85’,’23’,’19’]}, ) data_1[‘id’] = pd.to_numeric(data_1[‘id’], errors=’coerce’) data_1[‘date’] = pd.to_numeric(data_1[‘date’], errors=’coerce’) data_1[‘value’] = pd.to_numeric(data_1[‘value’], errors=’coerce’) I want to make this data_1 as follows: data_1=pd.DataFrame({‘id’:[1,1,1,2,2,2], ‘date’:[20220325,20220327,20220327,20220705,20220705,20220706], ‘wt’:[75,76,77,"","",85], ‘bmi’:[21,"","",19,18,19], ‘p’:[25,"","","","",23]}) I tried pivot_table ,but the output is not the same as I expected. …

Total answers: 2

Apply styler to pivot table

Apply styler to pivot table Question: I try to apply styler to the pivot table based on the next condition: if the percentage is in the range from 0 to 100, then color it yellow, if more than 100, then color it red, but after that I take a correction for another value df[‘Value’] and …

Total answers: 2