【发布时间】:2022-11-20 11:01:34
【问题描述】:
List = [0, 3, 2, 1]
This is the pandas dataframe i have.
| TIME | DATA | DMMA CODE | |
|---|---|---|---|
| 0 | 0 days 00:00:00 | Layer1 | B |
| 1 | 0 days 00:00:00 | Layer2 | S |
| 2 | 0 days 00:08:00 | Layer3 | B |
| 3 | 0 days 00:16:00 | Layer4 | S |
| 4 | 0 days 00:24:00 | Layer5 | B |
| 5 | 0 days 00:53:00 | Layer6 | S |
| 6 | 0 days 01:16:00 | Layer7 | B |
| 7 | 0 days 01:29:00 | Layer8 | S |
This is the end-result im trying to get.
| TIME | DATA | |
|---|---|---|
| 0 | 0 days 00:00:00 , 0 days 00:00:00 | Layer1 , Layer2 |
| 1 | 0 days 00:08:00 , 0 days 01:29:00 | Layer3 , Layer8 |
| 2 | 0 days 00:24:00 , 0 days 00:53:00 | Layer5 , Layer6 |
| 3 | 0 days 01:16:00 , 0 days 00:16:00 | Layer7 , Layer4 |
Basically index of the element inside "List" is the index of datas that have DMMA CODE of "B" and the element itself is the index of the datas that have DMMA CODE of "S".
First element of the list tells that "First CODE:B should be grouped with the first CODE:S"
Second element of the list tells that "Second CODE:B should be grouped with the fourth CODE:S" etc.
I am not familiar with pandas and couldn't even find a way to approach this problem.
【问题讨论】:
-
How would you do this outside of pandas?
标签: python pandas list dataframe