w3resource

Pandas Time Series: Exercises, Practice, Solution

[An editor is available at the bottom of the page to write and execute the scripts.]

Pandas Time Series [ 32 exercises with solution]

1. Write a Pandas program to create Go to the editor
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. Write a Pandas program to create Go to the editor
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. Write a Pandas program to create a date from a given year, month, day and another date from a given string formats. Go to the editor
Click me to see the sample solution

4. Write a Pandas program to print the day after and before a specified date. Also print the days between two given dates. Go to the editor
Click me to see the sample solution

5. Write a Pandas program to create a time-series with two index labels and random values. Also print the type of the index. Go to the editor
Click me to see the sample solution

6. Write a Pandas program to create a time-series from a given list of dates as strings. Go to the editor
Click me to see the sample solution

7. 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. Go to the editor
Click me to see the sample solution

8. Write a Pandas program to create a date range using a startpoint date and a number of periods. Go to the editor
Click me to see the sample solution

9. Write a Pandas program to create a whole month of dates in daily frequencies. Also find the maximum, minimum timestamp and indexs. Go to the editor
Click me to see the sample solution

10. Write a Pandas program to create a time series using three months frequency. Go to the editor
Click me to see the sample solution

11. Write a Pandas program to create a sequence of durations increasing by an hour. Go to the editor
Click me to see the sample solution

12. Write a Pandas program to convert year and day of year into a single datetime column of a dataframe.Go to the editor
Click me to see the sample solution

13. 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. Go to the editor
Click me to see the sample solution

14. Write a Pandas program to check if a day is a business day (weekday) or not. Go to the editor
Click me to see the sample solution

15. Write a Pandas program to get a time series with the last working days of each month of a specific year. Go to the editor
Click me to see the sample solution

16. Write a Pandas program to create a time series combining hour and minute. Go to the editor
Click me to see the sample solution

17. 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. Go to the editor
Click me to see the sample solution

18. Write a Pandas program to create a time series object with a time zone. Go to the editor
Click me to see the sample solution

19. Write a Pandas program to remove the time zone information from a Time series data. Go to the editor
Click me to see the sample solution

20. Write a Pandas program to subtract two timestamps of same time zone or different time zone. Go to the editor
Click me to see the sample solution

21. Write a Pandas program to calculate all Thursdays between two given days. Go to the editor
Click me to see the sample solution

22. Write a Pandas program to find the all the business quarterly begin and end dates of a specified year. Go to the editor
Click me to see the sample solution

23. Write a Pandas program to generate sequences of fixed-frequency dates and time spans intervals. Go to the editor
Click me to see the sample solution

24. Write a Pandas program to generate time series combining day and intraday offsets intervals. Go to the editor
Click me to see the sample solution

25. Write a Pandas program to extract the day name from a specified date. Add 2 days and 1 business day with the specified date. Go to the editor
Click me to see the sample solution

26. Write a Pandas program to convert integer or float epoch times to Timestamp and DatetimeIndex. Go to the editor
Click me to see the sample solution

27. 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. Go to the editor
Click me to see the sample solution

28. 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. Go to the editor
Click me to see the sample solution

29. 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. Go to the editor
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. Write a Pandas program to generate holidays between two dates using the US federal holiday calendar. Go to the editor
Click me to see the sample solution

31. Write a Pandas program to create a monthly time period and display the list of names in the current local scope. Go to the editor
Click me to see the sample solution

32. Write a Pandas program to create a yearly time period from a specified year and display the properties of this period. Go to the editor
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



Python: Tips of the Day

Combining Lists Using Zip:

  • Takes multiple collections and returns a new collection.
  • The new collection contains items where each item contains one element from each input collection.
  • It allows us to transverse multiple collections at the same time.
name = 'abcdef'
suffix = [1,2,3,4,5,6]
zip(name, suffix)
--> returns (a,1),(b,2),(c,3),(d,4),(e,5),(f,6)