Pandas Python: sort dataframe but don't include given row

后端 未结 1 1296
暗喜
暗喜 2020-12-21 11:14

I have df which looks like this:

Label                      Base
Label                          
Très à gauche              4.51
Très à droite             10         


        
1条回答
  •  囚心锁ツ
    2020-12-21 11:42

    You probably want to filter out the rows you don't want included in your sort operation:

    d = df_table
    condition = (d.Label=='A gauche') | (d.Label=='A droite')
    excluded = d[condition]
    included = d[~condition]
    

    Which can then be sorted

    sorted = included.sort(columns="Base",ascending=True)
    

    And if you want the excluded rows appended to the end of your data frame, you could do this:

    pandas.concat([sorted,excluded])
    

    0 讨论(0)
提交回复
热议问题