Data of date
While working with the data sets, many times we come across date and time columns. This column may contain the simple date in the day-month-year format, but there is further information hidden in it. For example, a date can tell you about the day of the week or quarter of the year.
Let's extract some information from the date column. Before playing with the date we need to check the format of the column.
The above image shows that the date is an object type. And on the object type, we cannot extract data related data. So we need to convert the same into date format.
Extract year: We can extract the year from the date column using pandas.Series.dt.year. This will extract the year from the date column and add it to the same data frame.
Extracting Month: Month details can be extracted from the date column using pandas.series.dt.month and pandas.series.dt.month_name(). This will extract the month and month name from the date and add it to the data frame.
Extracting day: We can extract the day of the month from the date column using pandas.series.dt.day.
Extracting day of the week: The date can easily tell you about the day of the month, but pandas can help us to get the day of the week using pandas.Series.dt.day_of_week.
Extracting day of week name: We can extract the day of week name using pandas.Series.dt.day_name.
Extract Week of year: In a year we have approx 48–50 weeks. Using dt.week we can extract the number of weeks of the year.
Extracting Quater: We have 4 quarters in a year. Using pandas.Series.dt.quarter we can extract the quarter of the year.
Extracting day of the year: A year has 365 days and pandas.Series.dt.day_of_year allows us to find the day of the year.
Pandas provides a variety of classes that can help us to extract more information from date column. Please refer to https://pandas.pydata.org/docs/reference/series.html for more details.
Hope you would have a good understanding of the date column.