0
0
Pandasdata~5 mins

dt accessor for datetime properties in Pandas - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the dt accessor in pandas?
The dt accessor allows you to access datetime properties and methods of pandas Series with datetime values, making it easy to extract parts like year, month, day, and more.
Click to reveal answer
beginner
How do you extract the year from a pandas Series of datetime values?
Use series.dt.year to get the year part of each datetime in the Series.
Click to reveal answer
intermediate
Which dt property would you use to get the day of the week as an integer (Monday=0)?
Use series.dt.dayofweek to get the day of the week as an integer where Monday is 0 and Sunday is 6.
Click to reveal answer
beginner
True or False: You can use dt accessor to convert datetime Series to strings.
True. Use series.dt.strftime() to format datetime as strings with the dt accessor.
Click to reveal answer
beginner
What will series.dt.hour return when applied to a datetime Series?
It returns the hour part (0 to 23) of each datetime value in the Series.
Click to reveal answer
Which pandas dt property gives the month number from a datetime Series?
Aseries.dt.month
Bseries.dt.day
Cseries.dt.year
Dseries.dt.hour
What does series.dt.dayofyear return?
ADay of the year (1 to 365 or 366)
BDay of the week as an integer
CDay of the month
DWeek number of the year
If you want to get the weekday name like 'Monday' from a datetime Series, which dt method do you use?
Aseries.dt.weekday
Bseries.dt.day_name()
Cseries.dt.dayofweek
Dseries.dt.weekday_name
Which of these is NOT a valid dt property in pandas?
Aseries.dt.minute
Bseries.dt.second
Cseries.dt.month_name()
Dseries.dt.hour_of_day
What type of pandas object must you have to use the dt accessor?
ASeries with string values
BDataFrame with any dtype
CSeries with datetime64 dtype
DList of datetime objects
Explain how to extract the year, month, and day from a pandas datetime Series using the dt accessor.
Think about the properties that give parts of a date.
You got /4 concepts.
    Describe how you would find the weekday name and the hour of the day from a datetime Series in pandas.
    One returns a string name, the other returns a number.
    You got /4 concepts.