File tree 3 files changed +41
-0
lines changed
solution/0100-0199/0178.Rank Scores
3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -122,4 +122,19 @@ FROM
122
122
) s;
123
123
```
124
124
125
+ ``` python
126
+ import pandas as pd
127
+
128
+
129
+ def order_scores (scores : pd.DataFrame) -> pd.DataFrame:
130
+ # Use the rank method to assign ranks to the scores in descending order with no gaps
131
+ scores[" rank" ] = scores[" score" ].rank(method = " dense" , ascending = False )
132
+
133
+ # Drop id column & Sort the DataFrame by score in descending order
134
+ result_df = scores.drop(" id" , axis = 1 ).sort_values(by = " score" , ascending = False )
135
+
136
+ return result_df
137
+
138
+ ```
139
+
125
140
<!-- tabs:end -->
Original file line number Diff line number Diff line change @@ -113,4 +113,19 @@ FROM
113
113
) s;
114
114
```
115
115
116
+ ``` python
117
+ import pandas as pd
118
+
119
+
120
+ def order_scores (scores : pd.DataFrame) -> pd.DataFrame:
121
+ # Use the rank method to assign ranks to the scores in descending order with no gaps
122
+ scores[" rank" ] = scores[" score" ].rank(method = " dense" , ascending = False )
123
+
124
+ # Drop id column & Sort the DataFrame by score in descending order
125
+ result_df = scores.drop(" id" , axis = 1 ).sort_values(by = " score" , ascending = False )
126
+
127
+ return result_df
128
+
129
+ ```
130
+
116
131
<!-- tabs:end -->
Original file line number Diff line number Diff line change
1
+ import pandas as pd
2
+
3
+
4
+ def order_scores (scores : pd .DataFrame ) -> pd .DataFrame :
5
+ # Use the rank method to assign ranks to the scores in descending order with no gaps
6
+ scores ["rank" ] = scores ["score" ].rank (method = "dense" , ascending = False )
7
+
8
+ # Drop id column & Sort the DataFrame by score in descending order
9
+ result_df = scores .drop ("id" , axis = 1 ).sort_values (by = "score" , ascending = False )
10
+
11
+ return result_df
You can’t perform that action at this time.
0 commit comments