我正在学习 Streamlit,以下代码在那里运行良好并给出了所需的输出,但是当我在我的系统中从 Sublime text 尝试了相同的代码(Sublime 作为文本编辑器和 anaconda 终端来运行 Streamlit),我得到了错误“ UndefinedVariableError:名称'injured_persons'未定义”
代码:
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)
阿波罗的战车
相关分类