Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Sort a dataframe by month name or by weekday name in chronological order

Project description


It sorts a dataframe by month names or by week names

Assume a dataframe has a month name column and one wants to sort the dataframe by month column in chronological order, this package helps to do that. This package can also be used to sort dataframe by weekday column.

How to install

pip install sort-dataframeby-monthorweek

There is another dependency package needs to be installed.

    pip install sorted-months-weekdays

There are 4 different functions in this package. We will see usage of below mentioned functions.



In this example we will see how to sort a sample dataframe by month name column

    import pandas as pd
	import itertools
    df = pd.DataFrame([['Feb',254],['Apr',420],['Jan',301],['Mar',449]],columns=['Month','Sales'])
      Month  Sales
    0   Feb    254
    1   Apr    420
    2   Jan    301
    3   Mar    449

Now, use Sort_Dataframeby_Month function to sort above dataframe

    df_sort = sort_dataframeby_monthorweek.Sort_Dataframeby_Month(df=df,monthcolumnname='Month')
      Month  Sales
    0   Jan    301
    1   Feb    254
    2   Mar    449
    3   Apr    420


In this example we will see how to sort a sample dataframe by weekday column

    df1 = pd.DataFrame([['Tue',25],['Thu',42],['Mon',30],['Wed',44]],columns=['Weekday','Sales'])
      Weekday  Sales
    0     Tue     25
    1     Thu     42
    2     Mon     30
    3     Wed     44

Now, use Sort_Dataframeby_Weekday function to sort df1

    df1_sort = sort_dataframeby_monthorweek.Sort_Dataframeby_Weekday(df=df1,Weekdaycolumnname='Weekday')
      Weekday  Sales
    0     Mon     30
    1     Tue     25
    2     Wed     44
    3     Thu     42

Above functions work for lower, upper and mixed case months or weekdays. It works for full names of months ('January') and weekdays ('Monday') as well.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for sort-dataframeby-monthorweek, version 0.4
Filename, size File type Python version Upload date Hashes
Filename, size sort_dataframeby_monthorweek-0.4.tar.gz (2.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page