0

Having an DataFrame like this:

    dest    departure    cars
0   A       2021-06-04   10
1   B       2021-06-04   4
2   C       2021-06-04   3

Imagine each row is part of a whole train and i want to aggregate the Dataframe that one row is one train. But i also want to know how many cars in this train go to which destination. The departure gives me information that this three rows belongs to one train so i think i have to group by the departure time.

Now i want a column for every destination and the number of cars as value like:

 departure   A   B  C
 2021-06-04  10  4  3

Which groupby function i have to call or is another function needed (like pandas.melt) ?

smytech
  • 55
  • 4
  • you want to pivot the data; pandas has as a pivot function: ``df.pivot('departure', 'dest', 'cars')``. Have a look at the docs for more info – sammywemmy Aug 05 '21 at 06:39

0 Answers0