File size: 2,004 Bytes
37c870e |
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 |
import streamlit as st
import pandas as pd
import numpy as np
#string
s = "Here's our first attempt to create a column"
#s
####################################### 2d data frame
df = pd.DataFrame({
"first column": [1, 2, 3, 4],
"second column": [10, 20, 30, 40]
})
#np generates makes n-dimensional homogeneous objects (10x20 table)
dataframe = np.random.randn(10, 20)
#pd generates two-dimensional data (10x20 table with labels columns)
dataframe2 = pd.DataFrame(
np.random.randn(10, 20),
columns = ('col %d' % i for i in range(20)),
index = ('row %d' % i for i in range(10))
)
#axis = 0 refer to column
#st.dataframe(dataframe2.style.highlight_max(axis=0))
#st.dataframe(dataframe)
#st.table(df)
############################################ chart
chart_data = pd.DataFrame(
np.random.randn(20, 3),
columns = ['a', 'b', 'd'])
#st.line_chart(chart_data)
############################################ map
map_data = pd.DataFrame(
np.random.randn(1000, 2) / [50, 50] + [37.76, -122.4],
columns = ["lat", "lon"])
#st.map(map_data)
########################################### widget
x = st.slider("x")
st.write(x, "squared is", x*x)
st.text_input("your name", key = "name")
#access usingst.session_state anytime
st.session_state.name
if st.checkbox("Show dataframe"):
chart_data = pd.DataFrame(
np.random.randn(20, 3),
columns = ["a", "b", "c"]
)
chart_data
df = pd.DataFrame({
"first column": [1, 2, 3, 4],
"second column": [10, 20, 30, 40]
})
st.write(df)
option2 = st.selectbox(
"Which column do you like best?",
[""] + list(df.columns)
)
if option2:
option = st.selectbox(
"Which nuber do you like best?",
df[option2]
)
"You selected: ", option
add_selectbox = st.sidebar.selectbox(
"How would you like to be contacted?",
("Email", "Home phone", "Mobile phone")
)
add_slider = st.sidebar.slider(
"Select a range of values",
0.0, 100.0, (25.0, 75.0)
)
|