Pandas Time Series: Exercises, Practice, Solution
This resource offers a total of 160 Pandas Time Series problems for practice. It includes 32 main exercises, each accompanied by solutions, detailed explanations, and four related problems.
[An Editor is available at the bottom of the page to write and execute the scripts.]
1. Datetime Object Creation
Write a Pandas program to create
a) Datetime object for Jan 15 2012.
b) Specific date and time of 9:20 pm.
c) Local date and time.
d) A date without time.
e) Current date.
f) Time from a datetime.
g) Current local time.
Click me to see the sample solution
2. Timestamp-Based Date Creation
Write a Pandas program to create
a) a specific date using timestamp.
b) date and time using timestamp.
c) a time adds in the current local date using timestamp.
d) current date and time using timestamp.
Click me to see the sample solution
3. Date Parsing from Components
Write a Pandas program to create a date from a given year, month, day and another date from a given string formats.
Click me to see the sample solution
4. Date Arithmetic
Write a Pandas program to print the day after and before a specified date. Also print the days between two given dates.
Click me to see the sample solution
5. Custom Time-Series with Index Labels
Write a Pandas program to create a time-series with two index labels and random values. Also print the type of the index.
Click me to see the sample solution
6. Time-Series from Date Strings
Write a Pandas program to create a time-series from a given list of dates as strings.
Click me to see the sample solution
7. Time-Series Filtering by Date Range
Write a Pandas program to create a time series object that has time indexed data. Also select the dates of same year and select the dates between certain dates.
Click me to see the sample solution
8. Date Range Generation
Write a Pandas program to create a date range using a startpoint date and a number of periods.
Click me to see the sample solution
9. Monthly Date Range and Analysis
Write a Pandas program to create a whole month of dates in daily frequencies. Also find the maximum, minimum timestamp and indexs.
Click me to see the sample solution
10. Quarterly Time-Series Creation
Write a Pandas program to create a time series using three months frequency.
Click me to see the sample solution
11. Sequence of Durations
Write a Pandas program to create a sequence of durations increasing by an hour.
Click me to see the sample solution
12. Convert Year and Day of Year to Datetime
Write a Pandas program to convert year and day of year into a single datetime column of a dataframe.
Click me to see the sample solution
13. Series of Timestamps from DataFrame
Write a Pandas program to create a series of Timestamps from a DataFrame of integer or string columns. Also create a series of Timestamps using specified columns.
Click me to see the sample solution
14. Business Day Check
Write a Pandas program to check if a day is a business day (weekday) or not.
Click me to see the sample solution
15. Last Working Days per Month
Write a Pandas program to get a time series with the last working days of each month of a specific year.
Click me to see the sample solution
16. Time Series Combining Hour and Minute
Write a Pandas program to create a time series combining hour and minute.
Click me to see the sample solution
17. Unix/Epoch Time Conversion
Write a Pandas program to convert unix/epoch time to a regular time stamp in UTC. Also convert the said timestamp in to a given time zone.
Click me to see the sample solution
18. Time Series with Time Zone
Write a Pandas program to create a time series object with a time zone.
Click me to see the sample solution
19. Remove Time Zone Information
Write a Pandas program to remove the time zone information from a Time series data.
Click me to see the sample solution
20. Subtracting Timestamps
Write a Pandas program to subtract two timestamps of same time zone or different time zone.
Click me to see the sample solution
21. Calculate All Thursdays Between Two Dates
Write a Pandas program to calculate all Thursdays between two given days.
Click me to see the sample solution
22. Business Quarterly Dates
Write a Pandas program to find the all the business quarterly begin and end dates of a specified year.
Click me to see the sample solution
23. Fixed-Frequency Date Sequences
Write a Pandas program to generate sequences of fixed-frequency dates and time spans intervals.
Click me to see the sample solution
24. Day and Intraday Offsets
Write a Pandas program to generate time series combining day and intraday offsets intervals.
Click me to see the sample solution
25. Extract Day Name and Adjust Dates
Write a Pandas program to extract the day name from a specified date. Add 2 days and 1 business day with the specified date.
Click me to see the sample solution
26. Convert Epoch Times to Timestamps
Write a Pandas program to convert integer or float epoch times to Timestamp and DatetimeIndex.
Click me to see the sample solution
27. Calculate Business Days and Month End
Write a Pandas program to calculate one, two, three business day(s) from a specified date. Also find the next business month end from a specific date.
Click me to see the sample solution
28. Period Index for Monthly Boundaries
Write a Pandas program to create a period index represent all monthly boundaries of a given year. Also print start and end time for each period object in the said index.
Click me to see the sample solution
29. PeriodIndex with Selective Year Extraction
Write a Pandas program create a series with a PeriodIndex which represents all the calendar month periods in 2029 and 2031. Also print the values for all periods in 2030.
Note: PeriodIndex is an immutable ndarray holding ordinal values indicating regular periods in time such as particular years, quarters, months, etc.
Click me to see the sample solution
30. Generate Holidays using US Federal Calendar
Write a Pandas program to generate holidays between two dates using the US federal holiday calendar.
Click me to see the sample solution
31. Monthly Time Period and Scope Listing
Write a Pandas program to create a monthly time period and display the list of names in the current local scope.
Click me to see the sample solution
32. Yearly Time Period Properties
Write a Pandas program to create a yearly time period from a specified year and display the properties of this period.
Click me to see the sample solution
Python Code Editor:
More to Come !
Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.
Test your Python skills with w3resource's quiz