Exploring Datasets with pandas and Matplotlib
We used pandas and Numpy for data wrangling, analysis, and visualization. The primary plotting library that we are exploring in the course is Matplotlib.
Dataset: Immigration to Canada from 1980 to 2013 - International migration flows to and from selected countries - The 2015 revision from United Nation's website.
Note: The dataset contains annual data on the flows of international migrants as recorded by the countries of destination. The data presents both inflows and outflows according to the place of birth, citizenship or place of previous / next residence both for foreigners and nationals. For this lesson, we will focus on the Canadian Immigration data.
1- Import data analysis modules: pandas and Numpy.
import numpy as np # useful for many scientific computing in Python
import pandas as pd # primary data structure library
2- Read Data:
df_can = pd.read_excel('https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DV0101EN-SkillsNetwork/Data%20Files/Canada.xlsx',
sheet_name='Canada by Citizenship',
skiprows=range(20),
skipfooter=2)
print ('Data read into a pandas dataframe!')
3- view the top 5 rows of the dataset using the
head()
function:df_can.head()
# tip: You can specify the number of rows you'd like to see as follows: df_can.head(10)
Waffle Charts
It is an interesting visualization that is normally created to display progress toward goals.
Word Clouds
is a depiction of the frequency of different words in some textual data.
Seaborn and Regression Plots
Is a python visualization library base on matplitlib, require less line of cod than matplotlib.
Code:
import seaborn as sns
ax = sns.regplot(x = 'year', y = 'total', data = df_tot, color='green' , marker='+') //x : horizontal, y: vertical
Folium
is a powerful Python library that helps you to create several types of leaflet maps.
Code
#define the world map
world_map = folium.Map()
#display world map
world_map
To create a Map of Canada
#define the wold map centred around Canada with a low zoom level
world_map = folium.Map(location=[56.130, -106.35], zoom_start=4)
#display world map
wold_map
To create different Map Styles using Stamen Toner or Stamen Terrain
wold_map = folium.Map(location=[56.130, -106.35], zoom_start=4, tiles='Stamen Toner')
wold_map
Maps with Markers
Add a Marker or add circle mark to the center of city (Ontario)
#define the wold map centred around Canada with a low zoom level
world_map = folium.Map(location=[56.130, -106.35], zoom_start=4)
#create Feature_group
Ontario = folium.map.FeatureGroup()
#style the feature group
Ontario.add_child(folium.features.CirclMarker([51.25, -85.32], radius = 5, color='red', fill_color = 'Red"))
#add the feature group to the map
canada_map.add_child(ontario)
#label the marker
folium.Marker([51.25, -05.32], popup='Ontario').add_to(canada_map)
#display world map
wold_map
Choropleth Maps
is a thematic map in which areas are shaded or patterned in proportion to the measurement of the statistical variable being displayed on the map, such as population density or per capita income.
Code:
0 Comments:
Post a Comment