awacke1 commited on
Commit
6acd8b1
·
1 Parent(s): 436b8f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -86
app.py CHANGED
@@ -37,95 +37,29 @@ def gen_load() -> pd.DataFrame:
37
 
38
  #AI Emotional State Score: Anxiety, Confusion, Trepidation, Fear, Guilt
39
 
 
 
 
40
 
41
- #queried_ctss = st.multiselect("Ctss",options=gen_load()["Ctss"].value_counts().reset_index())
42
- def load_data(state = None,zip_code = None,city = None,age = None,male = None,female = None,selected_cohorts = None) -> pd.DataFrame:
43
- df = gen_load()
44
- try:
45
- if (male or female) and not (male and female):
46
- df = df.loc[df['Gender'] == ("Male" if male else ("Female" if female else ""))]
47
- elif not (male or female):
48
- df = df.loc[df['Gender'] == "(null)"]
49
- except:
50
- pass
51
- try:
52
- df = df[(df['Age'].gt(age[0]) & df['Age'].lt(age[1]))]
53
- except:
54
- pass
55
- try:
56
- if zip_code or state or city:
57
- val = "Zip" if zip_code != "" else "City" if city != "" else "Abb"
58
- df = df.loc[df[val] == (zip_code or city or state)]
59
- except:
60
- pass
61
-
62
- try:
63
- if len(selected_cohorts) > 0:
64
- df = df.loc[df['Cohort'].isin(selected_ctss)]
65
-
66
- except:
67
- pass
68
-
69
- #value_counts = df["FCName"].value_counts()
70
- #df2 = pd.DataFrame(value_counts)
71
- #df2 = df2.reset_index()
72
- #df2.columns = ['FCName', 'Count']
73
- #df = df.merge(df2, left_on = 'FCName', right_on = 'FCName',how='left')
74
-
75
- return df
76
-
77
- def mapF(data):
78
- print(data)
79
- geo = data.iloc[0]
80
- print(geo)
81
- #print(geo[7], geo[8])
82
- #lat = float(geo['lat'])
83
- #lon = float(geo['lon'])
84
- lat = float(geo[7])
85
- lon = float(geo[8])
86
- max = data['Count'].max()
87
- view_state = pdk.ViewState(
88
- pitch = 40.5,
89
- bearing = -27.36,
90
- latitude = lat,
91
- longitude = lon,
92
- zoom = 4,
93
- )
94
 
95
- layer = pdk.Layer(
96
- 'ColumnLayer',
97
- data=data,
98
- get_position='[lon, lat]',
99
- pickable=True,
100
- extruded=True,
101
- auto_highlight=True,
102
- get_elevation="Count",
103
- # cell_size=200,
104
- radius = 1000,
105
- elevation_scale=1000000/ max,
106
- get_fill_color='[255, 255 - (Count/3500) * 255, 0,100]',
107
- coverage=10
108
- )
109
 
110
- r = pdk.Deck(
111
- # map_style = x,
112
- layers=[layer],
113
- initial_view_state= view_state,
114
- tooltip = {
115
- "html": "<b>City,State:</b> {City} </br> <b>Services:</b> {Count} </br> <b>F:</b> {FCName}",
116
- "style": {
117
- "backgroundColor": "steelblue",
118
- "color": "white"
119
- }
120
- },
121
- )
122
- # st.pydeck_chart(r)
123
- components.html(r.to_html(as_string=True), height=600)
124
 
125
- data = load_data(state=queried_state,zip_code=queried_zip_code,city=queried_city,age=queried_age,male=queried_male,female=queried_female)
 
126
 
127
- if st.checkbox('Display data ?'):
128
- data
 
129
 
130
- mapF(data)
131
-
 
37
 
38
  #AI Emotional State Score: Anxiety, Confusion, Trepidation, Fear, Guilt
39
 
40
+ import streamlit as st
41
+ import pandas as pd
42
+ import pydeck as pdk
43
 
44
+ def ShowCityDataframe(DATA_URL, SEARCH_DATA):
45
+ df = pd.read_csv(DATA_URL)
46
+ st.title("City FIPS, Location, and Population")
47
+ st.text("Search for any city in the United States:")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
+ # Search query for existing data
50
+ search_query = st.text_input(label="City Name", value="")
51
+ if search_query != "":
52
+ df = df[df["city"].str.contains(search_query, case=False)]
 
 
 
 
 
 
 
 
 
 
53
 
54
+ # Search query for new data
55
+ search_query2 = st.text_input(label="Zip Code", value="")
56
+ if search_query2 != "":
57
+ df = df[df["Zip"].str.contains(search_query2)]
 
 
 
 
 
 
 
 
 
 
58
 
59
+ st.subheader("City Detail")
60
+ st.write(df)
61
 
62
+ Cities = "uscities.csv"
63
+ SearchData = "US.txt"
64
+ ShowCityDataframe(Cities, SearchData)
65