In a data frame with 6 column a,b,c,d,e,f i want to sort a,b,c by a (ascending) and d,e,f by f (descending)
Asked
Active
Viewed 29 times
0
-
Not really , because i dont want to sort one column ascending and one column descending . i want to sort several column together by one of them – Nathan Oct 18 '22 at 12:34
-
I want to sort a,b,c by a and d,e,f by d – Nathan Oct 18 '22 at 12:35
-
that's what @GonçaloPeres's answer does – grymlin Oct 18 '22 at 12:35
-
There he says df.sort_values(['a', 'b'], ascending=[True, False]). its to sort a ascending and b descending . My problem is that the price , the quantity and the name are bound – Nathan Oct 18 '22 at 12:39
-
You want to sort, so why not just do it instead of asking? – Claudio Oct 18 '22 at 12:39
-
I dont understand. if i have a,b,c,d,e,f i want abc together and def together. I dont see this in the response of @GonçaloPeres – Nathan Oct 18 '22 at 12:41
-
Can you help me to understand – Nathan Oct 18 '22 at 12:42
-
It s not the same problem @Claudio – Nathan Oct 18 '22 at 12:43
-
@Nathan, you specify the ascending attribute with True and False for the columns that you like to be in ascending and ones you like in Descending. the answer linked shows exactly that syntax. hope it helps – Naveed Oct 18 '22 at 12:45
-
But price and qty are bound together . i dont want to specify wich column to sort in ascending or descending . i want to sort 3 column together by one of them and 3 together by one of them. How can i specify sort 3 column together – Nathan Oct 18 '22 at 12:48
-
1https://stackoverflow.com/questions/72593436/sort-a-selection-of-a-pandas-dataframe-only-keep-some-columns-fixed *( sort a selection of a pandas dataframe only (keep some columns fixed) )* answers your question. – Claudio Oct 18 '22 at 13:03
-
@Nathan : by editing your question the right answer appears now strange and not directly related to your question, so your edit wasn't helpful or being an improvement. Consider to accept the answer and rollback to the version of the question addressed by the given answer. By the way: what you ask for are two independent data frames saved in one data frame - this does not make much sense in the context of your question and resulted therefore in listing a not appropriate duplicate link. – Claudio Oct 18 '22 at 17:26
-
From the beginning my question was in this direction. you just didn't want to understand that the answer from the previous link was not the right one. – Nathan Oct 18 '22 at 19:39
-
Maybe it was not clear enough but I understood that the answer I was offered did not correspond – Nathan Oct 18 '22 at 19:40
1 Answers
0
I don't really know the easy way out but you could use this until someone point it out.
df_desc=self.orderbook_agreg_btc[["bids_qty","bids_price","exchange_name_bid"]].sort_values(["bids_price"],ascending= False)
df_asc=self.orderbook_agreg_btc[["asks_qty","asks_price","exchange_name_ask"]].sort_values(["asks_price"],ascending= True)
df = df_desc.append(df_asc)

Değer Donmaz
- 1
- 1