Covering the materials of Chapters 9-10.
Topics: tabular data, plotting and diagram visualization
Open and read the attached data/airports.csv
file, containing information about (larger) airports all over the world:
The columns in each row are delimited with ;
characters (instead of the default ,
).
import pandas as pd
airports = pd.read_csv('../data/airports.csv', delimiter=';')
display(airports)
Write a program that calculates and prints for each country the number of airports in that country. Sort the list by the number of airports.
display(airports.groupby('country').count()['iata'].sort_values(ascending=False))
Write a program that calculates and prints which city has the highest elevation. If a city has multiple airports, calculate the average (mean) elevation of the airports in that city.
display(airports.groupby('city').mean()['elevation'].idxmax())
Write a program that displays the city names which has at least 5 runways accumulated. Sort the city list by the number of runways decreasing and also display the number of runway in each city.
Note: keep in mind that a city might have multiple airports!
airports_city = airports.groupby('city').sum()
display(airports_city[airports_city['runways'] >= 5].sort_values(by='runways', ascending=False)['runways'])
Create a bar plot, displaying length of the longest runway for each airport. The aiports shall be sorted by the longest runway length (ascending). Visualize only the top 100 aiports, so the diagram will be readable. Set an appropriate figure size, so all bars and labels are readable.
import matplotlib.pyplot as plt
%matplotlib inline
airports.sort_values(by='longest').tail(100).plot(kind='bar', x='iata', y='longest', figsize=[20,4], width=0.7, label='longest runway')
plt.show()
Create a bar plot, displaying length of the longest runway for each city. The cities shall be sorted by the longest runway length (ascending). Visualize only the top 100 cities, so the diagram will be readable. Set an appropriate figure size, so all bars and labels are readable.
airports.groupby('city').max()['longest'].sort_values().tail(100).plot(kind='bar', figsize=[20,4], width=0.7, label='longest runway')
plt.show()