In [1]:
# Import all necessary libraries
import pandas as pd # The data processing library
import matplotlib as plot # The visualization library
import json # Library for encoding and decoding JSON data
In [2]:
# Load GeoJSON directly in a data frame
bad_geo_df = pd.read_json("../datasets/connectivity_2015_09.geojson")
bad_geo_df.head()
Out[2]:
In [3]:
# Load JSON and normalize nested JSON
with open("../datasets/connectivity_2015_09.geojson") as f:
geo_data = json.load(f)
tmp_df = pd.DataFrame(geo_data)
geo_df = pd.io.json.json_normalize(tmp_df['features'])
geo_df.head()
Out[3]:
In [4]:
# List the column headers
list(geo_df.columns.values)
Out[4]:
In [10]:
# Let's examine the coordinate
print geo_df['geometry.coordinates'][0], "\n"
print geo_df['geometry.coordinates'][1], "\n"
print geo_df['geometry.coordinates'][2], "\n"
In [28]:
# We can import a module wherever we want
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
from matplotlib.collections import PolyCollection
import numpy as np
%matplotlib inline
# Initialize a collection of Polygons
fig, ax = plt.subplots()
coll = PolyCollection(geo_df['geometry.coordinates'],
cmap=mpl.cm.jet,
edgecolors='none',
zorder=2,
color='blue')
ax.add_collection(coll)
ax.autoscale_view()
plt.show()
In [ ]: