w3resource

Pandas Datetime: Exercises, Practice, Solution


This resource offers a total of 125 Pandas Datetime problems for practice. It includes 25 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.]


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. Current Date

Write a Pandas program to create the todays date.

Click me to see the sample solution


2. UFO Sighting Days from Current Date

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. Date Range Analysis for UFO Sightings

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. Recent UFO Sightings (≤ 40 Years)

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. UFO Sightings Between Two Specific Dates

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. Extract UFO Sighting Years

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. Plot UFO Reports Per Year

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. Extract Date Components from UFO Reporting Date

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. Convert Datetime to Timestamp

Write a Pandas program to convert given datetime to timestamp.

Click me to see the sample solution


10. Year-Country Wise Frequency of UFO Reports

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. Extract Unique UFO Reporting Dates

Write a Pandas program to extract unique reporting dates of unidentified flying object (UFO).

Click me to see the sample solution


12. Calculate Difference Between Documented and Reporting Dates

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. Add 100 Days to UFO Reporting Date

Write a Pandas program to add 100 days with reporting date of unidentified flying object (UFO).

Click me to see the sample solution


14. Generate Fixed-Frequency Date Sequences

Write a Pandas program to generate sequences of fixed-frequency dates and time spans.

Click me to see the sample solution


15. Conversion Between Strings and Datetime

Write a Pandas program to create a conversion between strings and datetime.

Click me to see the sample solution


16. Manipulate Datetime with Timezone Information

Write a Pandas program to manipulate and convert date times with timezone information.

Click me to see the sample solution


17. Average Mean of UFO Sighting Reports

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. Graphical Analysis of UFO Sightings by Year

Write a Pandas program to create a graphical analysis of UFO (unidentified flying object) Sightings year.

Click me to see the sample solution


19. Check Missing Values in UFO DataFrame

Write a Pandas program to check the empty values of UFO (unidentified flying object) Dataframe.

Click me to see the sample solution


20. Plot Distribution of UFO Observation Time

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. Graphical Analysis of UFO Sightings by Month

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. Top 10 UFO Years vs. Hours of the Day

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. Top 10 UFO Years vs. Each Month

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. Heatmap for Top 10 UFO Years vs. Each Month

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. Timewheel: Hour vs. Year Comparison for Top 10 UFO Years

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.