I am learning streamlit and when I was going through a tutorial video ,where access to remote desktop was already provided, which has all the prerequisite (Atom as text editor & streamlit ) the following code worked well there and gave the required output, However when I tried the same code in my system(Sublime as text editor & anaconda terminal to run streamlit) from Sublime text I got the error "UndefinedVariableError: name 'injured_persons' is not defined"
CODE :
import streamlit as st
import pandas as pd
import numpy as mp
DATA_URL=("E://Saumya//STUDY//DS//Motor_Vehicle_Collisions_-_Crashes.csv")
st.title("Motor Vehicle Collsion in New york City")
st.markdown("This application is to analyze motor vehicle collision in NYC")
@st.cache(persist=True)
def load_data(nrows):
data=pd.read_csv(DATA_URL,nrows=nrows,parse_dates=[['CRASH DATE','CRASH TIME']])
data.dropna(subset=['LATITUDE', 'LONGITUDE'], inplace=True)
lowercase=lambda x : str(x).lower()
data.rename(lowercase,axis='columns',inplace=True)
data.rename(columns={'crash_date_crash_time' : 'date/time'},inplace=True)
return data
data=load_data(100000)
st.header("How many people are injured")
injured_people = st.slider("Number of people injured", 0, 19)
st.map(data.query("injured_persons>= @injured_people")[["latitude", "longitude"]].dropna(how="any"))
if st.checkbox("Show Raw data",False):
st.subheader("Raw Data")
st.write(data)
Most probably it's happening because
'injured_persons'
is not in yourdata
.for example:
if I try to access a column name
D
which is not in my DataFrameit throws me an error
Please check if you
data
has'injured_persons'
. you can do so byprint('injured_persons' in data.columns)