【发布时间】:2021-01-14 05:33:37
【问题描述】:
我正在学习 streamlit,当我浏览教程视频时,已经提供了对远程桌面的访问,它具有所有先决条件(Atom 作为文本编辑器和 streamlit),以下代码在那里运行良好并提供了所需的输出, 但是,当我在我的系统中尝试相同的代码(Sublime 作为文本编辑器和 anaconda 终端运行 streamlit)时,我收到错误“UndefinedVariableError: name 'injured_persons' is not defined”
代码:
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)
【问题讨论】:
-
您从该错误消息中了解到什么?此外,除非绝对必要,否则请不要将信息作为图像共享。请参阅:meta.stackoverflow.com/questions/303812/…、idownvotedbecau.se/imageofcode、idownvotedbecau.se/imageofanexception。