Ratha
Ratha

Reputation: 9692

defining month first dateformat in pandas?

How can i define month first dateformat in pandas?

for date first format I define like using dayfirst attribute;

 dateCols = ['Document Date']
 data = pd.read_excel(os.path.join(delivery_path, f), parse_dates=dateCols,
                                 dayfirst=True, sheet_name='Refined', skiprows=1)

There is no monthfirst attribute. How should I define that when reading the file? And also what is the default dateformat panda uses when reading date columns?

eg: October 1st =10/01/2019

Upvotes: 0

Views: 637

Answers (1)

Jjj
Jjj

Reputation: 649

I don't understand your date column is like this October 1st=10/01/2019 or this 10/01/2019 if your column is October 1st=10/01/2019

import pandas as pd
def clean(date_column):
    date = str(date_column).split('=')
    return date[1]

data[dateCols] = pd.to_datetime(data[dateCols].apply(clean),format='%m/%d/%Y')

if 10/01/2019

data[dateCols] = pd.to_datetime(data[dateCols],format='%m/%d/%Y')

for the format you can learn more about from here http://strftime.org/

Upvotes: 1

Related Questions