'create and save dataframes from other dataframe
An extract from my df (35k rows in total):
stop_id time
7909 2022-04-06T03:47:00+03:00
7909 2022-04-06T04:07:00+03:00
1009413 2022-04-06T04:10:00+03:00
1002246 2022-04-06T04:19:00+03:00
1009896 2022-04-06T04:20:00+03:00
I want to create separate dataframes for every unique stop_id column, in each dataframe I need to have stop_id (which is constant for every row), time field with only unique values and number column which aggregates the rows with the same time value. So, assuming there are 50 unique stop_id values, I want to get 50 separate csv files containing all the data above. How can I do this?
hope the explanation doesn't seem messy
I have this line of code
df.groupby(['time']).agg({'time':'size','stop_id': ", ".join})
but it doesn't keep the value of stop_id
expected output: csv1
stop_id time number
7909 2022-04-06T03:47:00+03:00 1
7909 2022-04-06T04:07:00+03:00 1
7909 2022-04-06T05:00:00+03:00 2
...
csv2
stop_id time number
1009413 2022-04-06T04:10:00+03:00 1
1009413 2022-04-06T04:19:00+03:00 3
1009413 2022-04-06T04:30:00+03:00 5
...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
