Introduction to Dates Manipulation
Explore the essentials of date manipulation in Pandas to analyze and extract insights from time-based data. Learn to convert columns to datetime, access date components, generate date ranges, and resample data. This lesson prepares you to answer interview questions on identifying patterns and trends in dates for various datasets.
We'll cover the following...
Concept
Date parsing and manipulation is a cornerstone of Data Analysis. Fortunately for you, Pandas has great utility functions allowing you to easily analyze date/time data.
Travel dataset
Idea
If you have the dates of travel of your clients, there are types of analysis you can do:
- You can find which months or seasons your clients prefer to travel during.
- You can dissect the above even further, for instance, to see if there’s a difference in travel patterns between Europeans and Americans
- You can develop seasonal forecasts based on previous data
Interviews
You can be asked questions such as:
- How can you implement adding a “season of travel” column, based on the rule that each season begins on a specific date?
- Can you identify the most common month of travel for people of British nationality?
Medical dataset
Idea
If you have the dates on which patients developed certain symptoms, you can do some analysis on that data, such as:
- Effect of short or long-term smoking on patients in relation to other health conditions
- The most common age of the onset of diabetes or heart disease on patients
Interviews
You can be asked questions such as the following:
- Can you find any trends in your data for diseases becoming more prevalent? (This can be achieved by finding the count of patients who have developed each disease per year, and seeing if there is an increasing trend in a specific disease.)
- Can you find the most common effects of certain habits, such as smoking?
Before you move to the challenges
- Make sure you know how to convert a column to
datetime - Make sure you know the accessors from a
datetimecolumn, such as fetching a month from a date value - Make sure you know how to generate a range of dates
- Make sure you know what resampling is, or how to group by a specific date range, such as years or months