Lecture 3: Data visualization#

“Data visualization”, “chart”, “graph”, and will be used interchangeably.

Please sign attendance sheet

Today’s goal: Visualizing requests per community district#

This should help us better understand trends across the city.

Start by importing necessary packages#

import pandas as pd
import plotly.express as px

Populations#

Load the data:

population = pd.read_csv("https://data.cityofnewyork.us/api/views/xi7c-iiu2/rows.csv")
population.head()
Borough CD Number CD Name 1970 Population 1980 Population 1990 Population 2000 Population 2010 Population
0 Bronx 1 Melrose, Mott Haven, Port Morris 138557 78441 77214 82159 91497
1 Bronx 2 Hunts Point, Longwood 99493 34399 39443 46824 52246
2 Bronx 3 Morrisania, Crotona Park East 150636 53635 57162 68574 79762
3 Bronx 4 Highbridge, Concourse Village 144207 114312 119962 139563 146441
4 Bronx 5 University Hts., Fordham, Mt. Hope 121807 107995 118435 128313 128200

Adapting the basic histogram example:

fig = px.histogram(
    population,
    x="Borough",
    title="Number of community districts in each borough",
)
fig.show()