Skip to content

Instantly share code, notes, and snippets.

import folium
import pandas as pd
country_geo = 'world-countries.json'
data = pd.read_csv('Indicators.csv')
data.shape
data.head()
# select Life expectancy for females for all countries in 2013
hist_indicator = 'Life expectancy at birth'
hist_year = 2013
mask1 = data['IndicatorName'].str.contains(hist_indicator)
mask2 = data['Year'].isin([hist_year])
# apply our mask
stage = data[mask1 & mask2]
stage.head()
# Setup a folium map at a high-level zoom
map = folium.Map(location=[100, 0], zoom_start=1.5)
# choropleth maps bind Pandas Data Frames and json geometries.
#This allows us to quickly visualize data combinations
map.choropleth(geo_data=country_geo, data=plot_data,
columns=['CountryCode', 'Value'],
key_on='feature.id',
fill_color='YlGnBu', fill_opacity=0.7, line_opacity=0.2,
legend_name=hist_indicator)
map.save('plot_data.html')
# Import the Folium interactive html file
from IPython.display import HTML
HTML('<iframe src=plot_data.html width=700 height=450></iframe>')
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# Importing the libraries
import pandas as pd
# read the training data and store data in DataFrame titled housing_data
housing_data = pd.read_csv('../Desktop/iowa_housing/train.csv')
Step2: Exploring the Data
#display the first five rows of the data
house_data.head()
#display the first five rows of the data
house_data.head()
Id MSSubClass MSZoning LotFrontage LotArea Street Alley LotShape LandContour Utilities ... PoolArea PoolQC Fence MiscFeature MiscVal MoSold YrSold SaleType SaleCondition SalePrice
0 1 60 RL 65.0 8450 Pave NaN Reg Lvl AllPub ... 0 NaN NaN NaN 0 2 2008 WD Normal 208500
1 2 20 RL 80.0 9600 Pave NaN Reg Lvl AllPub ... 0 NaN NaN NaN 0 5 2007 WD Normal 181500
2 3 60 RL 68.0 11250 Pave NaN IR1 Lvl AllPub ... 0 NaN NaN NaN 0 9 2008 WD Normal 223500
# AOI co-ordinates (created via geojson.io)
geojson_geometry = {
"type": "Polygon",
"coordinates": [
[
[438.2666015625,22.27893059841188],
[440.013427734375,22.27893059841188],
[440.013427734375,23.33216830631147],
[438.2666015625,23.33216830631147],
[438.2666015625,22.27893059841188]
# get images that overlap with our AOI
geometry_filter = {
"type": "GeometryFilter",
"field_name": "geometry",
"config": geojson_geometry
}
# get images acquired within a date range
date_range_filter = {
"type": "DateRangeFilter",