I need an idea how to write the dataframe horizontally, and no repeat the 'ProblemCode' column

Question:

currently:

ProblemGroup month Count
A 1 362
A 2 485
B 1 400
B 2 487

I need it this way:

month A B
1 362 400
2 485 487
Asked By: Rodrigo Fernandes

||

Answers:

You can use pivot_table for that

import pandas as pd

data = [["A", 1, 362], ["A", 2, 485], ["B", 1, 400], ["B", 2, 487]]
df = pd.DataFrame(data, columns=["ProblemGroup", "Month", "Count"])
pd.pivot_table(df, values="Count", index="Month", columns="ProblemGroup")

outputs:

ProblemGroup    A    B
Month                 
1             362  400
2             485  487
Answered By: bitflip
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.