Linked Questions

1 vote
1 answer
10k views

How to sort a Pandas DataFrame with multiple columns, some in ascending order and others descending order? [duplicate]

How can I sort a Pandas DataFrame according to multiple columns, with some of the columns being sorted in ascending order while other columns are sorted in descending order? Furthermore, assume that ...
Felipe D.'s user avatar
  • 1,291
2 votes
2 answers
4k views

How to sort dataframe rows by multiple columns [duplicate]

I'm having trouble formatting a dataframe in a specific style. I want to have data pertaining to one S/N all clumped together. My ultimate goal with the dataset is to plot Dis vs Rate for all the S/Ns....
LeafTeaNeko's user avatar
-1 votes
1 answer
947 views

How to simultaneously sort columns in pandas dataframe [duplicate]

Suppose that I want to sort a data frame in Pandas and my data frame looks like this First Name Last Name Street Address Type 0 Joe Smith 123 Main St. Property ...
Fentonb123's user avatar
0 votes
1 answer
621 views

how to sort a dataframe based on column based on other column [duplicate]

How can I sort a data frame based on column which is again dependent on other column ? DF : A B C ww a 70 ww b 90 ww c 100 qq a 100 qq b 80 qq c 90 rr a 80 rr b 70 rr c ...
learner's user avatar
0 votes
1 answer
474 views

How to group rows together based on their column value? [duplicate]

I have a data frame which looks like this df = pd.DataFrame({'Animal': ['Falcon', 'Falcon','Parrot', 'Parakeet'], 'Color': ['Black', 'White', 'Green','Green'], '...
yawwml's user avatar
  • 87
-1 votes
1 answer
516 views

How to sort multiple columns with different orders in pandas? [duplicate]

How do I sort a data frame using multiple columns such that each column is sorted in different order? For example, the primary sort key is column 'A' in ascending order and secondary sort key is ...
fatdragon's user avatar
  • 2,309
0 votes
1 answer
570 views

How to sort pandas data frame ascending and descending for different values? [duplicate]

I apologize if the wording for this question is strange. I wasn't sure how to phrase it. I have a python pandas data frame like this: data = pd.DataFrame({"a":[1,4,5,4,2], "b":[1,1,...
Ryan Slattery's user avatar
0 votes
1 answer
406 views

I want to sort my pandas dataframe using two different columns [duplicate]

I have a csv data that contains soccer predictions. I sorted it using sort_values(by=["total_predicted_goals"]. My problem now is to let the dates be sorted by descending or ascending order....
stan001's user avatar
  • 13
0 votes
0 answers
353 views

Sort multiple columns and return table within Pandas DataFrame [duplicate]

I'm doing some analysis on customers behaviors upon using internet banking versus offline channel. I have imported excel database into pandas DataFrame #Read Excel file using pandas excel_file = '...
aarnphm's user avatar
  • 107
0 votes
1 answer
234 views

Pandas group by and sorting by values within the group [duplicate]

After running XGBoost and getting the prediction, I need to sort the ranks withing the based on group id. I've tried several methods but was unsuccessful. My data: id hotel_id rank 1 5 ...
Robert's user avatar
  • 151
0 votes
1 answer
139 views

how sort rows with respect of a group? [duplicate]

Hi i have panda data frame. I wana sort data with respect of a group id and sorting with respect of order id title order 2 A 2 2 B 1 2 C 3 3 H ...
user avatar
-1 votes
1 answer
217 views

Sort data frame in ascending order by mean of other column [duplicate]

I have a data frame: df = ID Num a 3 b 4 b 2 a 1 Want to sort in ascending order by taking into account unique values of ID column My Try: df.sort_values(by=['Num']) But it gave me ...
Mamed's user avatar
  • 772
0 votes
3 answers
102 views

Reindex a Pandas Dataframe [duplicate]

I have a pandas dataframe in Python. datetime machineID 0 2021-10-01 00:00:00 1.0 1 2021-10-01 00:00:00 2.0 2 2021-10-01 00:00:00 3.0 3 2021-10-01 00:...
PeakyBlinder's user avatar
  • 1,137
0 votes
1 answer
70 views

How can I group by id and sort and numerate for days? [duplicate]

everyone! I am a pandas learner and I have no idea how can I solve it! Please, help me! I have a table like this: id sales_day number of purchases 1 Monday 100 2 ...
Mike Silver's user avatar
0 votes
2 answers
81 views

How to rearrange rows with multiple columns in python dataframe [duplicate]

I have the following dataset: Name Year Date Value x year1 date1 v1 x year1 date2 v2 x year1 date3 v3 x year2 date1 v4 x year2 date2 v5 x year2 date3 v6 z year1 date1 v7 z ...
pythonspyder's user avatar

15 30 50 per page
1
2 3 4 5