April 13, 2023 at 8:48 pm
I have the following data frame:
df = pd.DataFrame({'A': [6,0, 4,2, 8, 2, 6,0, 4,8],
'B': range(0, 12),
'C': ['a', 'b','c', 'd', 'e','a', 'b','c', 'd', 'e']})
A B C
0 6 0 a
1 0 1 b
2 4 2 c
3 2 3 d
4 8 4 e
--------------- partition by C
5 2 5 a
6 6 6 b
7 0 7 c
8 4 8 d
9 8 9 e
My final data frame is as follows:
import pandas as pd
import random as rand
df = pd.DataFrame({'A': [0, 2, 4, 6, 8,0, 2, 4, 6, 8],
'B': range(0, 12),
'C': ['a', 'b','c', 'd', 'e','a', 'b','c', 'd', 'e']})
A B C
0 0 0 a
1 2 1 b
2 4 2 c
3 6 3 d
4 8 4 e
--------------- partition by C
5 0 5 a
6 2 6 b
7 4 7 c
8 6 8 d
9 8 9 e
As you can see, I have a partition from a to e in the C column of the data frame, and I need to sort the A column depending on the partitions in C. I couldn't come up with a good solution. This is similar to Partition by in SQL.
I need to sort the values of two columns partition by partition, just like we do in SQL partition by partition, as described in this manual. In this case, I explain why I require it.
April 14, 2023 at 9:10 pm
Thanks for posting your issue and hopefully someone will answer soon.
This is an automated bump to increase visibility of your question.
April 27, 2023 at 8:58 am
Have you tried using groupby() and apply() functions in pandas?
May 16, 2023 at 8:11 am
This was removed by the editor as SPAM
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply