-
- Notifications
You must be signed in to change notification settings - Fork 19.4k
Closed
Labels
AlgosNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffBugIndexRelated to the Index class or subclassesRelated to the Index class or subclassesgood first issue
Description
I found some problems while using data_frame sort_index, first, create dataframe
data = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), columns=['a', 'b', 'c']) data = data.set_index('a') data.sort_index(level=['a'], ascending=[False]) Then I want to sort index "a" in descending order,
data.sort_index(level=['a'], ascending=[False]) The above code does not sort index a in descending order, I found the reason is that this dataframe is a single index structure, so when ascending = list is passed, it does not take effect
Lines 4777 to 4783 in bf613c1
| if level is not None: | |
| new_axis, indexer = labels.sortlevel( | |
| level, ascending=ascending, sort_remaining=sort_remaining | |
| ) | |
| elif isinstance(labels, ABCMultiIndex): |
Because when it is used, the index may be single index or multi-index. In order to use the effect uniformly,I think there should be a judgment here. If index is a single index and ascending type == list, ascending should be equal to ascending [0],This may be more user friendly
If yes, can I mention pr
Metadata
Metadata
Assignees
Labels
AlgosNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffBugIndexRelated to the Index class or subclassesRelated to the Index class or subclassesgood first issue