How to separate the poles independently?



  • import pandas as pd
    
    df = pd.read_excel('random.xlsx')
    df.sort_values(['Name','Birthday','City of birth','Favorite color of the rainbow', 'Favorite subject at school'], ascending = [True])
    df
    

    The problem is, it only sorts the first column, and it needs everything.

    Ексель файл

    I added a picture of the table. We need each pole to be sorted separately.
    For example, the name column was sorted alphabet, column 2 by date, column 3 by alphabet, column 4 and 5 also by alphabet.



  • Working example:

    In [124]: np.random.seed(42)
    

    In [125]: df = pd.DataFrame(np.random.randint(20, size=(5, 3)), columns=list("abc"))

    In [126]: df
    Out[126]:
    a b c
    0 6 19 14
    1 10 7 6
    2 18 10 10
    3 3 7 2
    4 1 11 5

    In [127]: res = pd.DataFrame(np.sort(df, axis=0), columns=df.columns)

    In [128]: res
    Out[128]:
    a b c
    0 1 7 2
    1 3 7 5
    2 6 10 6
    3 10 11 10
    4 18 19 14

    NOTE: If you're sorted like this, you've got ties in your rows, that is, all columns will be sorted. independently of each other♪ The fact that before the grading belonged to one row may be scattered in different lines. That's the only way to realize what you described on the question.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2