pivot-table

split rows into columns in pandas dataframe

split rows into columns in pandas dataframe Question: I have table similar to this table: id val 0 abc_1 5 1 abc_1 3 2 abc_1 7 3 abc_2 12 4 abc_2 6 5 abc_2 9 … I want to "split" the rows into columns based on the id, so the result should be: id val1 …

Total answers: 2

pandas/python : Get each distinct values of each column as columns and their counts as rows

pandas/python : Get each distinct values of each column as columns and their counts as rows Question: I have a data frame like this with below code, df=pd.DataFrame(columns=[‘col1’, ‘col2’, ‘col3’]) df.col1=[‘q1’, ‘q2’, ‘q2’, ‘q3’, ‘q4’, ‘q4’] df.col2=[‘b’, ‘a’, ‘a’, ‘c’, ‘b’, ‘b’] df.col3=[‘p’, ‘q’, ‘r’, ‘p’, ‘q’, ‘q’] df col1 col2 col3 0 q1 b …

Total answers: 1

Creating a pivot table with multiple columns

Creating a pivot table with multiple columns Question: I’m trying to create a pivot table with multiple columns; I’m unsure how to explain this better. But the following is the desired output, dataframe setup, and code I have tried so far. Desired Output: Dataframe Setup: data = { ‘WholesalerID’: {0: 121, 1: 121, 2: 42, …

Total answers: 1

How to convert columns to rows Datewise in Python

How to convert columns to rows Datewise in Python Question: I have a data in the following format Date AA_ZZ_CR AA_ZZ_BT AA_XX_CR AA_XX_BT BB_ZZ_CR BB_ZZ_BT BB_XX_CR BB_XX_BT 20230202 20 56 34 556 29 59 32 559 20230203 21 45 54 423 28 48 53 426 20230204 22 78 23 790 27 76 29 794 20230205 …

Total answers: 2

How to format and color monetary numbers in Pandas dataframe?

How to format and color monetary numbers in Pandas dataframe? Question: I’m trying to apply formatting to a pandas pivot table so that it has color formatting and number formatting with commas, no decimals, $ in front of the number and parenthesis for negatives. import numpy as np import pandas as pd money = [10000000, …

Total answers: 1

Pandas sort multilevel columns with year and month

Pandas sort multilevel columns with year and month Question: I have created a pivotable in pandas with multilevel columns, but the order of columns are not sorted – Year 2022 2021 2023 Month Jan Feb Mar Jan Dec Jun What I want: Year 2021 2022 2023 Month Jan Mar Jan Feb Jun Dec How can …

Total answers: 1

Reshape excel table with stacked date column

Reshape excel table with stacked date column Question: I have an excel file that has diffrent weather stations and the minimum and maximum temprature of every month in a year like this: Name Time Minimum Maximum Station 1 2020-01 -10 2 … … … 2020-12 -5 0 Station 2 2020-01 -8 4 … … … …

Total answers: 1

Aggregate hourly data and count duplicates in pandas python

Aggregate hourly data and count duplicates in pandas python Question: I have a dataframe df that looks like this: time Hit/Miss 2016-09-29 08:00:00 FN 2016-09-29 08:30:00 FN 2016-09-29 09:45:00 TP 2016-10-05 14:00:00 FP time is imported straight from a csv file without being set as an index, and Hit/Miss contains three categorical values FN, TP, …

Total answers: 1

Pandas – Compute sum of a column as week-wise columns

Pandas – Compute sum of a column as week-wise columns Question: I have a table like below containing values for multiple IDs: ID value date 1 20 2022-01-01 12:20 2 25 2022-01-04 18:20 1 10 2022-01-04 11:20 1 150 2022-01-06 16:20 2 200 2022-01-08 13:20 3 40 2022-01-04 21:20 1 75 2022-01-09 08:20 I would …

Total answers: 3

Removing duplicate row values but creating new columns

Removing duplicate row values but creating new columns Question: I have a table that looks similar to the following: Miles Side Direction Param1 Width Height Date 0.5 Left Right 5 0.6 0.8 2023-01-04 0.5 Right Right 5 0.5 0.9 2023-01-04 1 Left Left 4 0.3 0.3 2023-01-04 1 Right Left 4 0.5 0.5 2023-01-04 As …

Total answers: 2