I am trying to use Choropleth from Plotly Express to plot data in US zip codes. I have a GeoJSON from this GitHub repo (https://github.com/ndrezn/zip-code-geojson) and am trying to use it in conjunction with a CSV which gives zip codes and the number of train stations in that zip code. CSV format looks like this: zip code data frame format
My code is copied below. This results in a TypeError: Object of type bytes is not JSON serializable.
The error is throwing on the fig.show() line; when I just create the figure and do not try to show it, no error is thrown.
import json
from google.colab import files
import pprint
import pandas as pd
import plotly.express as px
nj_geo_data = files.upload()
## Using files.upload, select the appropriate GeoJSON file
train_df = pd.read_csv("Train Data.csv", converters={'zipcodes': str})
fig = px.choropleth(train_df, geojson = nj_geo_data,
locations='Train Station?',
featureidkey = 'properties.ZCTA5CE10',
projection='mercator')
fig.show()
Tina is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.