top of page

Machine learning - Working with Pandas Date and time

Updated: Mar 23, 2021

Before start machine learning and with python Pandas it is necessary to know the complete information regarding the Date and Time Functionality.


Here we will be working with some examples for your better understating the time and date and extract useful information from Date and time.


Machine learning - Working with Pandas Date and time
Machine learning - Working with Pandas Date and time

How to use these, date and time series in python pandas:


strftime(directive):


This function used to find result as per given directives, here we working with CSV, and simple python script and find a date, month as per the given date.


Working with simple python code:


Here some example which we will work using the above sheets:


>>>date = '11/15/2019'


now we find the date and its day as per date


>>>dt = datetime.strptime(date, '%b')


Working with CSV date column:


Finding months


Date formate, date = '11/15/2019'


>>>training = training= pd.read_csv('training.csv')


>>>months = pd.to_datetime(training['date']).dt.strftime('%b').unique()

>>>months_list = list(months)


Result show as:



Finding month and days both:



It may help to data science when we need to plots data when the date was given but need days to set as a label then we need to find days from the date, here


Use some time to ticks graph:


>>>plt.xticks(np.arange(0, 5000, 1000), months_list)


Contact here, if you face any problem regarding python data science and machine learning.
bottom of page