-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstreamlit_exploration.py
126 lines (76 loc) · 3.22 KB
/
streamlit_exploration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import streamlit as st
# To make things easier later, we're also importing numpy and pandas for
# working with sample data.
import numpy as np
import pandas as pd
st.title('Climate Data Exploration')
st.write("A subtitle, once I know what I'm doing")
@st.cache
def load_data():
us_cities = pd.read_csv("us_cities.csv")
return us_cities
us_cities = load_data()
example = us_cities.head()
number_rows = 100000
st.write("The first "+str(number_rows)+" rows of the US portion of the all cities CSV file loaded as a pandas dataframe")
example
us_cities_test = us_cities
city= st.sidebar.selectbox(
'Which number do you like best?',
us_cities_test['City'].unique())
city2 = "Houston"
us_cities2 = pd.read_csv("us_cities.csv")
us_cities_test = us_cities2[us_cities2['City'] == city]
us_cities_test2 = us_cities2[us_cities2['City'] == "Houston"]
us_cities_test
st.write("The first X rows of the dataframe")
us_cities_test_ColSubset = us_cities_test[["AverageTemperature","AverageTemperatureUncertainty","dt"]]
us_cities_test_ColSubset2 = us_cities_test2[["AverageTemperature","AverageTemperatureUncertainty","dt"]]
us_cities_test_ColSubset.set_index("dt",inplace=True)
us_cities_test_ColSubset2.set_index("dt",inplace=True)
# data[data['Country'] == "United States"]
st.write(city)
#us_cities_test_ColSubset
st.line_chart(us_cities_test_ColSubset,width=1000, height=400,use_container_width=False)
st.write("Houston")
st.line_chart(us_cities_test_ColSubset2,width=1000, height=400,use_container_width=False)
#us_cities_test_ColSubset2
st.write("Example of df used in Charts")
us_cities_test_ColSubset
# st.write("Exp Merge")
# merge_exp = pd.merge([us_cities_test_ColSubset,us_cities_test_ColSubset2],right="City")
# st.line_chart(merge_exp,width=1000, height=400,use_container_width=False)
# us_cities_test
# st.write(type(us_cities_test))
us_cities_test = us_cities_test.rename(index=str,columns = {'Latitude':'latitude'})
us_cities_test = us_cities_test.rename(index=str,columns = {'Longitude':'longitude'})
us_cities_test
def fixCoordinates2(df,latitude_str,longitude_str):
df[latitude_str] = df[latitude_str].str.replace("N","").astype(float)
df[longitude_str] = df[longitude_str].str.replace("W","")
df[longitude_str] = '-' + df[longitude_str].astype(str)
df[longitude_str] = df[longitude_str].astype(float)
return df
us_cities_test_fixed2 = fixCoordinates2(us_cities_test,"latitude","longitude")
us_cities_test_fixed2_subset = us_cities_test_fixed2[["AverageTemperature","latitude","longitude"]]
us_cities_test_fixed2_subset = us_cities_test_fixed2_subset[0:500]
us_cities_test_fixed2_subset
# st.map(us_cities_test_fixed2_subset)
# st.deck_gl_chart(
# viewport={
# 'latitude': min(us_cities_test_fixed2_subset['latitude']),
# 'longitude': min(us_cities_test_fixed2_subset['longitude']),
# 'zoom': 11,
# 'pitch': 50,
# },
# layers=[{
# 'type': 'ScatterplotLayer',
# 'data': us_cities_test_fixed2_subset,
# 'getRadius':10,
# 'getFillColor':[255,25,0]
# }])
# map_data = pd.DataFrame(
# np.random.randn(1000, 2) / [50, 50] + [37.76, -122.4],
# columns=['latitude', 'longitude'])
# map_data
# st.map(map_data)