I want to rebulid my dataframe from df1 to df2:
df1 like this:
id | counts | days |
---|---|---|
1 | 2 | 4 |
1 | 3 | 4 |
1 | 4 | 4 |
2 | 56 | 8 |
2 | 37 | 9 |
2 | 10 | 7 |
2 | 10 | 4 |
df2 like this:
id | countsList | daysList |
---|---|---|
1 | '2,3,4' | '4,4,4' |
2 | '56,37,10,10' | '8,9,7,4' |
where countsList and daysList in df2 is a str.
I have about 1 million lines of df1, it would be very slow if I using for
iter.
So I want to using groupby and apply to achieve it. Do you have any solution or efficient way to cover it.
My computer info:
CPU: Xeon 6226R 2.9Ghz 32core
RAM: 16G
python:3.9.7