|  | 
| 6 | 6 | 
 | 
| 7 | 7 | 
 | 
| 8 | 8 | DATA_URL = ( | 
| 9 |  | - "C:/Users/Atharva/Desktop/Project/project 2/streamlit-nyc/Motor_Vehicle_Collisions_-_Crashes.csv" | 
|  | 9 | + "Motor_Vehicle_Collisions_-_Crashes.csv" | 
| 10 | 10 | ) | 
| 11 | 11 | 
 | 
| 12 | 12 | st.title("Motor Vehicle Collisions in New York City") | 
| @@ -70,15 +70,20 @@ def load_data(nrows): | 
| 70 | 70 | st.header("Top 5 dangerous streets by affected type") | 
| 71 | 71 | select=st.selectbox('Affected type of people', ['Pedestrians', 'Cyclists', 'Motorists']) | 
| 72 | 72 | 
 | 
| 73 |  | -if select == 'Pedestrains': | 
| 74 |  | - st.write(original_data.query("injured_pedstrains >=1")[["on_street_name", "injured_pedstrains"]].sort_values(by=['injured_pedstrains'], ascending=False).dropna(how='any')[:5]) | 
| 75 |  | - | 
| 76 |  | -elif select == 'Cyclists': | 
| 77 |  | - st.write(original_data.query("injured_cyclists >=1")[["on_street_name", "injured_cyclists"]].sort_values(by=['injured_cyclistss'], ascending=False).dropna(how='any')[:5]) | 
| 78 |  | - | 
| 79 |  | -else: | 
| 80 |  | - st.write(original_data.query("injured_motorists >=1")[["on_street_name", "injured_motorists"]].sort_values(by=['injured_motorists'], ascending=False).dropna(how='any')[:5]) | 
| 81 |  | - | 
|  | 73 | +selectbox_dict = { | 
|  | 74 | + 'Pedestrians': 'injured_pedestrians', | 
|  | 75 | + 'Cyclists': 'injured_cyclists', | 
|  | 76 | + 'Motorists': 'injured_motorists' | 
|  | 77 | +} | 
|  | 78 | + | 
|  | 79 | +injured_type = selectbox_dict[select] | 
|  | 80 | +st.write( | 
|  | 81 | + original_data.query(f"{injured_type} >=1")[ | 
|  | 82 | + ["on_street_name", injured_type] | 
|  | 83 | + ] | 
|  | 84 | + .sort_values(by=[injured_type], ascending=False) | 
|  | 85 | + .dropna(how="any")[:5] | 
|  | 86 | +) | 
| 82 | 87 | 
 | 
| 83 | 88 | if st.checkbox("Show Raw Data", False): | 
| 84 | 89 | st.subheader('Raw Data') | 
|  | 
0 commit comments