-4

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

but i need it to be like this:

enter image description here

Pythona
  • 7
  • 5
  • 5
    I am voting to close this question since I am pretty sure it's already been answered [here](https://stackoverflow.com/questions/37787698/how-to-sort-pandas-dataframe-from-one-column). – Derek O Feb 09 '22 at 18:33
  • 3
    Repetitive question. Multiple answers available already. Please search before posting :) – LeNan18 Feb 09 '22 at 18:37

1 Answers1

0

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
richardec
  • 14,202
  • 6
  • 23
  • 49