0
0
Data Analysis Pythondata~5 mins

Extracting date components (year, month, day) in Data Analysis Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What Python library is commonly used to work with dates and times in data analysis?
The pandas library is commonly used because it has powerful tools to handle dates and times easily.
Click to reveal answer
beginner
How do you extract the year from a pandas datetime column named date?
Use df['date'].dt.year to get the year part from each date in the column.
Click to reveal answer
beginner
What does df['date'].dt.month return?
It returns the month number (1 for January, 2 for February, etc.) for each date in the date column.
Click to reveal answer
beginner
How can you extract the day of the month from a pandas datetime column?
Use df['date'].dt.day to get the day number (1 to 31) from each date.
Click to reveal answer
beginner
Why is it useful to extract year, month, and day from a datetime column?
Extracting these parts helps analyze data by time periods, like grouping sales by year or finding trends by month.
Click to reveal answer
Which pandas attribute extracts the month from a datetime column?
A.dt.month
B.dt.year
C.dt.day
D.dt.hour
What type of data must a pandas column be to use .dt.year?
AString
BFloat
CDatetime
DInteger
If you want to get the day of the month from a datetime column, which code is correct?
Adf['date'].dt.month
Bdf['date'].dt.day
Cdf['date'].dt.year
Ddf['date'].day
What does df['date'].dt.year return?
AYear number
BDay number
CMonth number
DHour number
Why might you extract date parts like year or month from a datetime column?
ATo change the date format
BTo delete the date column
CTo convert dates to strings
DTo analyze data by time periods
Explain how to extract the year, month, and day from a pandas datetime column.
Think about the pandas datetime accessor .dt and its attributes.
You got /4 concepts.
    Describe why extracting date components is helpful in data analysis.
    Consider how time-based patterns are found in data.
    You got /3 concepts.