Instagram
youtube
Facebook
Twitter

Sort a Pandas DataFrame in Ascending Order by a Specific Column

    Sort a Pandas DataFrame in Ascending Order by a Specific Column
     
     Short Description of the Program:

     This program reads a CSV file into a DataFrame and sorts it in ascending order by the values in the 'Age' column.
     
      Explanation:

  • sort_values(by='Age')
    Sorts the DataFrame by the 'Age' column in ascending order by default.

     
  • You can sort by other columns too, like 'Name' or 'Cit

Program:

import pandas as pd

df = pd.read_csv('data.csv')

sorted_df = df.sort_values(by='Age')

print(sorted_df)