0
0
Pandasdata~30 mins

Datetime type in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Working with Datetime Type in pandas
📖 Scenario: You work in a small company that tracks employee attendance. You have a list of dates when employees checked in. You want to analyze these dates using pandas to understand attendance patterns.
🎯 Goal: You will create a pandas DataFrame with date strings, convert these strings to datetime type, filter dates after a certain day, and finally print the filtered dates.
📋 What You'll Learn
Create a pandas DataFrame with a column of date strings
Create a variable with a date threshold as a datetime object
Filter the DataFrame to keep only dates after the threshold
Print the filtered dates
💡 Why This Matters
🌍 Real World
Datetime data is everywhere: tracking attendance, sales dates, sensor logs, and more. Being able to convert and filter dates helps analyze trends over time.
💼 Career
Data scientists and analysts often work with time series data. Knowing how to handle datetime types in pandas is a key skill for cleaning and analyzing such data.
Progress0 / 4 steps
1
Create a pandas DataFrame with date strings
Import pandas as pd. Create a DataFrame called df with one column named 'check_in' containing these exact date strings: '2024-01-10', '2024-02-15', '2024-03-20', '2024-04-25', '2024-05-30'.
Pandas
Need a hint?

Use pd.DataFrame and pass a dictionary with key 'check_in' and the list of date strings as value.

2
Create a datetime threshold variable
Create a variable called threshold_date by converting the string '2024-03-01' to a pandas datetime object using pd.to_datetime().
Pandas
Need a hint?

Use pd.to_datetime('2024-03-01') to convert the string to datetime.

3
Convert 'check_in' column to datetime and filter dates
Convert the 'check_in' column in df to datetime type using pd.to_datetime(). Then create a new DataFrame called filtered_df that contains only rows where 'check_in' is after threshold_date.
Pandas
Need a hint?

Use df['check_in'] = pd.to_datetime(df['check_in']) to convert the column. Then filter with df[df['check_in'] > threshold_date].

4
Print the filtered dates
Print the filtered_df DataFrame to show only the dates after threshold_date.
Pandas
Need a hint?

Use print(filtered_df) to display the filtered DataFrame.