Loading [MathJax]/extensions/AssistiveMML.js
Skip to main content
Beta
This lesson is in the beta phase, which means that it is ready for teaching by instructors outside of the original author team.
Interactive Data Visualizations in Python
Visualization is an important part of both exploratory data analysis
and communicating results
Interactivity allows us to visualize more information without
overcomplicating a single plot
use conda env create --file environment.yml
to create a
new environment from a YAML file
see a list of all environments with conda env list
activate the new environment with
conda activate <NAME>
see a list of all installed packages with
conda list
Import your CSV using
pd.read_csv('<FILEPATH>')
Transform your dataframe from wide to long with
pd.melt()
Split column values with
df['<COLUMN>'].str.split('<DELIM>')
Sort rows using df.sort_values()
Export your dataframe to CSV using
df.to_csv('<FILEPATH>')
Before visualizing your dataframe, make sure it only includes the
rows you want to visualize. You can use pandas’ query()
function to easily accomplish this
To make a line plot with px.line
, you need to specify
the dataframe, X axis, and Y axis
If you want to have multiple lines, you also need to specify what
column determines the line color
In a Jupyter Notebook, you need to call fig.show()
to
display the chart
The entire streamlit app must be saved in a single python file,
typically app.py
To run the app locally, enter the bash command
streamlit run app.py
Add a title with st.title('Title')
, and other text with
st.write('## Markdown can go here')
Make sure your dataframes and figures are stored in variables,
typically df
for a dataframe and fig
for a
figure
To display a plotly figure, use
st.plotly_chart(fig)
In order to add widgets, we need to refactor our code to make it
more flexible.
f-Strings allow you to easily insert variables into a string
All Streamlit apps must have a GitHub repo with the code, data, and
environment files
You can deploy up to 3 apps for free with Streamlit Cloud