How to sort date in excel using Pandas?

In these articles, We will discuss how to import an excel file in a single Dataframe and sort the Date in a given column on. Suppose our Excel file looks like these:

sample_date.xlsx

To get the excel file used click here.

Approach :

  • Import Pandas module
  • Make DataFrame from Excel file
  • sort the date column with DataFrame.sort_value() function
  • Display the Final DataFrame

Step 1: Importing pandas module and making DataFrame form excel.

Python3



filter_none

edit
close

play_arrow

link
brightness_4
code

# import module
import pandas as pd
  
# making data frame from excel file
df = pd.read_excel('excel_work\sample_date.xlsx')
  
print("Original DataFrame")
df

chevron_right


Output :

Step 2: Sorting date with DataFrame.sort_value() function.

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# sorting date with sort_value() function
Final_result = df.sort_values('Joining Date')
  
print(" Sorted Date DataFrame")
Final_result

chevron_right


Output :

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.