w3resource

Pandas Datetime: Exercises, Practice, Solution

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

Pandas Datetime [25 exercises with solution]

ufo.csv

Extraterrestrials, visitors, little green men, UFOs, swap gas. What do they want? Where do they come from? Do they like cheeseburgers? This dataset will likely not help you answer these questions. It does contain over 80,000 records of UFO sightings dating back as far as 1949. With the latitude and longitude data it is possible to assess the global distribution of UFO sightings (patterns could aid in planetary defense if invasion proves to be imminent). The dates and times, along with the duration of the UFO's stay and description of the craft also lend themselves to predictions. Can we find patterns in their arrival times and durations? Do aliens work on weekends? Help defend the planet and learn about your fellow earthlings (and when they are most likely to see ET).

Pandas Datetime Exercises

Data Sources: ufo_sighting_data.csv - [80,332 records]

Exercises data sources: ufo.csv - [347 random records from ufo_sighting_data.csv]

Content

Column Name Description
Date_time standardized date and time of sighting
city location of UFO sighting
state/province the US state or Canadian province, appears blank for other locations
country Country of UFO sighting
UFO_shape a one word description of the "spacecraft"
length_of_encounter_seconds standardized to seconds, length of the observation of the UFO
described_duration _of_encounter raw description of the length of the encounter (shows uncertainty to previous column)
description text description of the UFO encounter. Warning column is messy, with some curation it could lend itself to some natural language processing and sentiment analysis.
date_documented when was the UFO sighting reported
latitude latitude
longitude longitude

Note: There are no missing data in the columns (ufo.csv).

Source:

(a) https://github.com/planetsig/ufo-reports (b) https://www.kaggle.com/camnugent/ufo-sightings-around-the-world

1. Write a Pandas program to create the todays date.
Click me to see the sample solution

2. Write a Pandas program to calculate all the sighting days of the unidentified flying object (ufo) from current date.
Click me to see the sample solution

3. Write a Pandas program to get the current date, oldest date and number of days between Current date and oldest date of Ufo dataset.
Click me to see the sample solution

4. Write a Pandas program to get all the sighting days of the unidentified flying object (ufo) which are less than or equal to 40 years (365*40 days).
Click me to see the sample solution

5. Write a Pandas program to get all the sighting days of the unidentified flying object (ufo) between 1950-10-10 and 1960-10-10.
Click me to see the sample solution

6. Write a Pandas program to get all the sighting years of the unidentified flying object (ufo) and create the year as column.
Click me to see the sample solution

7. Write a Pandas program to create a plot to present the number of unidentified flying object (UFO) reports per year.
Click me to see the sample solution

8. Write a Pandas program to extract year, month, day, hour, minute, second and weekday from unidentified flying object (UFO) reporting date.
Click me to see the sample solution

9. Write a Pandas program to convert given datetime to timestamp.
Click me to see the sample solution

10. Write a Pandas program to count year-country wise frequency of reporting dates of unidentified flying object(UFO).
Click me to see the sample solution

11. Write a Pandas program to extract unique reporting dates of unidentified flying object (UFO).
Click me to see the sample solution

12. Write a Pandas program to get the difference (in days) between documented date and reporting date of unidentified flying object (UFO).
Click me to see the sample solution

13. Write a Pandas program to add 100 days with reporting date of unidentified flying object (UFO).
Click me to see the sample solution

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

15. Write a Pandas program to create a conversion between strings and datetime.
Click me to see the sample solution

16. Write a Pandas program to manipulate and convert date times with timezone information.
Click me to see the sample solution

17. Write a Pandas program to get the average mean of the UFO (unidentified flying object) sighting was reported.
Click me to see the sample solution

18. Write a Pandas program to create a graphical analysis of UFO (unidentified flying object) Sightings year.
Click me to see the sample solution

19. Write a Pandas program to check the empty values of UFO (unidentified flying object) Dataframe.
Click me to see the sample solution

20. Write a Pandas program to create a plot of distribution of UFO (unidentified flying object) observation time.
Click me to see the sample solution

21. Write a Pandas program to create a graphical analysis of UFO (unidentified flying object) sighted by month.
Click me to see the sample solution

22. Write a Pandas program to create a comparison of the top 10 years in which the UFO was sighted vs the hours of the day.
Click me to see the sample solution

23. Write a Pandas program to create a comparison of the top 10 years in which the UFO was sighted vs each Month.
Click me to see the sample solution

24. Write a Pandas program to create a heatmap (rectangular data as a color-encoded matrix) for comparison of the top 10 years in which the UFO was sighted vs each Month.
Click me to see the sample solution

25. Write a Pandas program to create a Timewheel of Hour Vs Year comparison of the top 10 years in which the UFO was sighted.
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.

[ Want to contribute to Python Pandas exercises? Send your code (attached with a .zip file) to us at w3resource[at]yahoo[dot]com. Please avoid copyrighted materials.]

Test your Python skills with w3resource's quiz



Follow us on Facebook and Twitter for latest update.