0

I have:

df = pd.DataFrame(
    [
        [ab, bc, cd],
        [de, ef, fg],
        [gh, hi, ij],
    ],
    columns=list("c1", "c2", "c3")
)

And I'd like to have:

 df = pd.DataFrame(
        [
            [c1, ab],
            [c1, de],
            [c1, gh],
            [c2, bc],
            [c2, ef],
            [c2, hi],
            [c3, cd],
            [c3, fg],
            [c3, ij]
        ],
        columns=list("col1", "col2")
    )

The format should take the previous column name, insert into the first column with the entries in the second. How can I achieve this in pivot table?

pymat
  • 1,090
  • 1
  • 23
  • 45

0 Answers0