python - Multi Index Sorting in Pandas -
i have dataset multi-index columns in pandas df sort values in specific column. have tried using sortindex , sortlevel haven't been able results looking for. dataset looks like:
group1 group2 b c b c 1 1 0 3 2 5 7 2 5 6 9 1 0 0 3 7 0 2 0 3 5
i want sort info , index column c in grouping 1 in descending order results like:
group1 group2 b c b c 2 5 6 9 1 0 0 1 1 0 3 2 5 7 3 7 0 2 0 3 5
is possible sort construction info in, or should swapping group1 index side?
when sorting multiindex need contain tuple describing column within list*:
in [11]: df.sort([('group1', 'c')], ascending=false) out[11]: group1 group2 b c b c 2 5 6 9 1 0 0 1 1 0 3 2 5 7 3 7 0 2 0 3 5
* so not confuse pandas thinking want sort first group1 c.
python sorting pandas multi-index
No comments:
Post a Comment