Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to Order the column values to make it more readable

this is example of my code. i need to reorder the values to be more readable.

data = {'code 1':[123, 422 , 123, 868, 422],
        'code 2':[53673, 3773, 387892, 17994, 2358]
         'Company':['GRM', 'SER', 'MEM','NOE', 'SEE']
          'Product_weight': [29,23,122,19,22]}
 df = pd.DataFrame(data)  

this is the actual table:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

but i need it to be like this:

enter image description here

>Solution :

Try using sort_values:

df = df.sort_values('code 1')

Output:

>>> df
   code 1  code 2 Company  Product_weight
0     123   53673     GRM              29
2     123  387892     MEM             122
1     422    3773     SER              23
4     422    2358     SEE              22
3     868   17994     NOE              19
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading