How to sort pandas data frame using values from several columns?

前端 未结 7 1173
走了就别回头了
走了就别回头了 2020-12-02 09:33

I have the following data frame:

df = pandas.DataFrame([{\'c1\':3,\'c2\':10},{\'c1\':2, \'c2\':30},{\'c1\':1,\'c2\':20},{\'c1\':2,\'c2\':15},{\'c1\':2,\'c2\'         


        
7条回答
  •  感情败类
    2020-12-02 10:24

    Use of sort can result in warning message. See github discussion. So you might wanna use sort_values, docs here

    Then your code can look like this:

    df = df.sort_values(by=['c1','c2'], ascending=[False,True])
    

提交回复
热议问题