Question: UFO Python Download the ufo _ sightings.csv file that is located on this web page to the same directory where your Program 6 python file

UFO Python Download the ufo_sightings.csv file that is located on this web page to the same directory where your Program 6 python file is located.
Use pandas and/or matplotlib to produce two different visualizations that help the user gain insight into the information contained in the csv file. 20 points - pandas and/or matplotlib are used to produce two insightful visualizations. All or nothing.
20 points - Each visualization is a different type. For example, one visualization could be a bar chart and the other could be a pie chart. All or nothing.
10 points - The visualizations use the underlying data to show different things. All or nothing.
20 points - All aspects of each visualization are clearly labeled. 3 points for each type of improvement up to 20 points.
5 points - The first visualization yields an interesting insight that is explained in a comment at the top of your program. For example, if the program visualized the Montana population by decade, the population is flat to decreasing from 1920 to 1940. This is interesting because populations normally increase and is explained by drought and depression.
5 points - The second visualization yields an interesting insight that is explained in a comment at the top of your program, similar to the requirement for the first visualization.
20 points - The Python solution is properly commented, easy to understand and does not contain unnecessary code. 3 points for each type of improvement up to 20 points.
code:
# Importing required libraries
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
# First Visualization: Number of UFO Sightings by Year
# This visualization helps us understand the trend of UFO sightings over time
# Interesting insight: The number of UFO sightings seems to increase significantly after the 1950s
# 1910 lowest recorded year
def site2year(datafile):
fig = plt.figure()
ax = fig.add_subplot()
ax.hist(datafile['Dates.Documented.Year'], bins=range(1999,2015), align='right')
ax.set_title('Number of UFO Sightings by Year')
ax.set_xlabel('Year')
ax.set_ylabel('Number of Sightings')
plt.xticks(rotation=0) # Get or set the current tick locations and labels of the x-axis.
plt.xlim(left=min(datafile['Dates.Documented.Year'].min(),1999))
plt.xlim(right=max(datafile['Dates.Documented.Year'].max(),2015))
plt.grid()
plt.gca().set_facecolor('#f5f5f5')
#plt.savefig('ufo_sightings_by_year.png') # saves a fancy image
plt.show()
print("The first visualization reveals an increase in UFO sightings after 1999.")
# Second Visualization: Distribution of UFO Shapes
# This visualization helps us understand the most common shapes reported for UFOs
# Interesting insight: Circular shapes are the most commonly reported UFO shapes
def distshape(datafile):
fig = plt.figure()
ax = fig.add_subplot()
ax.pie(datafile['Data.Shape'].value_counts().sort_index(), labels=datafile['Data.Shape'].value_counts().index, autopct='%1.1f%%')
ax.axis('equal')
ax.set_title('Distribution of UFO Shapes')
plt.show()
print("The second visualization shows that circular type shapes are the most common UFO shapes reported.")
def main():
# Loading the CSV file into a DataFrame
ufo_data = pd.read_csv('ufo_sightings.csv') # reads file from panda, pd.
site2year(ufo_data)
distshape(ufo_data)
main()
# print(ufo_data.columns)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!