0

I have a dataframe df with:

df = pd.DataFrame(
    {
        "place": [2, 2, 2, 2, 2, 2],
        "date": [
            "2021-02-28",
            "2021-02-28",
            "2021-03-31",
            "2021-03-31",
            "2021-04-30",
            "2021-04-30",
        ],
        "special_handling": [1, 0, 1, 0, 1, 0],
        "count": [100, 200, 500, 600, 300, 400],
    }
)
place date special_handling count
2 2021-02-28 1 100
2 2021-02-28 0 200
2 2021-03-31 1 500
2 2021-03-31 0 600
3 2021-04-30 1 300
3 2021-04-30 0 400

I would like to transform the column "special_handling" into 2 separate columns to reduce the number of rows for a better overview per place/date

place date special_handling_0 special_handling_1
2 2021-02-28 200 100
2 2021-03-31 600 500
3 2021-04-30 400 300

How can I do this in pandas?

And does this sort of transformation have a special name? I didn't know what to search for.

Vega
  • 2,272
  • 4
  • 21
  • 37

0 Answers0