Skip to main content

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

Project description

sort-dataframeby-monthorweek

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.

    Sort_Dataframeby_Month
    Sort_Dataframeby_Weekday

Example1

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'])
    df
    Out: 
      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')
    df_sort
    Out:
      Month  Sales
    0   Jan    301
    1   Feb    254
    2   Mar    449
    3   Apr    420

Example2

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'])
    df1
    Out: 
      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')
    df1_sort
    Out: 
      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

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page