r/learnpython • • 20m ago

Looking a way to combine columns based on values.

I wish to alter a table/dataframe like this one:

TypeAlphaTypeBetaTypeGamma
A100A80A90
B20B40B30
C1C1C0
X1Y2Z1

Into something looking like this one:

TypeAlphaBetaGamma
A1008090
B202030
C110
X1nannan
Ynan2nan
Znannan1

To combine data based on shared values so it is easier to compare different types.

How could I do this with Python?

1 Upvotes

1 comment sorted by

•

u/seanv507 3m ago

have you asked google ai? use pandas or polars

create 3 dataframes from each pair of columns, renaming/formatting to type| key|value (where key = Alpha/Beta/Gamma for each corresponding dataframe)

then concatenate the 3 dataframes

then pivot on key