Why does my Pandas DataFrame not display new order using `sort_values`?

前端 未结 2 1895
广开言路
广开言路 2020-11-27 07:05

New to Pandas, so maybe I\'m missing a big idea? I have a Pandas DataFrame of register transactions with shape like (500,4):

Time                       


        
相关标签:
2条回答
  • 2020-11-27 07:27

    df.sort_values(['Total Due']) returns a sorted DF, but it doesn't update DF in place.

    So do it explicitly:

    df = df.sort_values(['Total Due'])
    

    or

    df.sort_values(['Total Due'], inplace=True)
    
    0 讨论(0)
  • 2020-11-27 07:31

    My problem, fyi, was that I wasn't returning the resulting dataframe, so PyCharm wasn't bothering to update said dataframe. Naming the dataframe after the return keyword fixed the issue.

    Edit: I had return at the end of my method instead of return df, which the debugger must of noticed, because df wasn't being updated in spite of my explicit, in-place sort.

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