pivot

Python – trouble pivoting, grouping, and summing dataframe columns

Python – trouble pivoting, grouping, and summing dataframe columns Question: I have this code. I need to group by CustomerName and then sum the filegroups. def consolidated_df(): df = breakdown_df() df.pivot_table(index=’CustomerName’, columns=’FileGroup’, aggfunc="sum") return df breakdown_df() looks like ID CustomerName FileGroup Size Size(Bytes) 1 CustomerA Database 99.8 M 104667648 1 CustomerA Database 99.8 M 104667648 …

Total answers: 2

Can we make the values in pandas.pivot_table() a count of column?

Can we make the values in pandas.pivot_table() a count of column? Question: pd.pivot_table(df, index = col1, columns = col2, value = ?) I want the values to be the count of values in col 1.The values in col 1 are all strings. I basically want to imitate what is happening in the excel file pictured …

Total answers: 1

Slick pivot and mapping in Python

Slick pivot and mapping in Python Question: I wish to create column headers from the type values. Then map the appropriate en value under the newly formed headers. Data country start type en US 8/1/2022 bb 10 Japan 8/1/2022 aa 25 Japan 9/1/2022 cc 1 Desired country start aa bb cc US 8/1/2022 0 10 …

Total answers: 1

Best way to create pivot tables for multiple dataframes?

Best way to create pivot tables for multiple dataframes? Question: I have 4 data frames and trying to create pivot tables for each data frame. Instead of combining or concatenating into one large table, I’d like to create a pivot table for each dataframe, which means I would end up with 4 separate pivot tables. …

Total answers: 1

Pivoting DataFrame in Python Pandas

Pivoting DataFrame in Python Pandas Question: I’m trying to pivot my df from wide to long, and I am attempting to replicate R’s dplyr::pivot_longer() function. I have tried pd.wide_to_long() and pd.melt() but have had no success in correctly formatting the df. I also attempted using df.pivot() and come to the same conclusion. Here is what …

Total answers: 1

How to pivot by keeping the index as year and month python

How to pivot by keeping the index as year and month python Question: I am trying to group values by Year month, from my dataset by using below code pd.to_datetime(All_Insurer_Portal_Reindex[‘New_Booking/Issued Date’]).dt.month.value_counts().sort_index().to_frame() But ending up by getting this PFA screen shot enter image description here but I am want this type of output PFA screen shot …

Total answers: 1

Pandas Group transpose single colum and row in Python

Pandas Group transpose single colum and row in Python Question: I’m trying to group a pandas dataframe and transpose one single column and one single row(?). See example image below. I have tried using the function GroupBy and Pivot. Any ideas? 🙂 Example grouped table import pandas as pd name = ‘Name’ account = ‘Account’ …

Total answers: 1

Percentage of Row Total in Heatmap Python

Percentage of Row Total in Heatmap Python Question: I would like to show the numbers as percentage of Row (or Column) Total for this heatmap. I am using Plotly library for the plotting. I could find a way to get the percentage of row total using code below. I would really appreciate any help to …

Total answers: 1