Pandas dataframe sort

Posted under » Python Data Analysis on 25 August 2024

To sort

taik1 = [10, 20, 40, 15]

taik2 = ['pun', 'dek', 'shanmugam', 'LKY']

import pandas as pd

mydataset = {
    'hid' : taik1,
    'animal' : taik2
}

df = pd.DataFrame(mydataset)

sorted_df = df.sort_values(by='animal')
print(sorted_df)

    hid     animal
3   15        LKY
1   20        dek
0   10        pun
2   40  shanmugam

The index by default will be shown on the first column. In order to hide it, you need to

print(sorted_df.to_string(index=False))

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS data