-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
15 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,24 @@ | ||
import numpy as np | ||
import pandas as pd | ||
import streamlit as st | ||
from streamlit_condition_tree import condition_tree, config_from_dataframe | ||
import pandas as pd | ||
|
||
df = pd.read_csv( | ||
'https://drive.google.com/uc?id=1phaHg9objxK2MwaZmSUZAKQ8kVqlgng4&export=download', | ||
index_col=0, | ||
parse_dates=['Date of birth'], | ||
date_format='%Y-%m-%d') | ||
df['Age'] = ((pd.Timestamp.today() - df['Date of birth']).dt.days / 365).astype(int) | ||
df['Sex'] = pd.Categorical(df['Sex']) | ||
df['Likes tomatoes'] = np.random.randint(2, size=df.shape[0]).astype(bool) | ||
from streamlit_condition_tree import condition_tree, config_from_dataframe | ||
|
||
st.dataframe(df) | ||
# Initial dataframe | ||
df = pd.DataFrame({ | ||
'First Name': ['Georges', 'Alfred'], | ||
'Age': [45, 98], | ||
'Favorite Color': ['Green', 'Red'], | ||
'Like Tomatoes': [True, False] | ||
}) | ||
|
||
# Basic field configuration from dataframe | ||
config = config_from_dataframe(df) | ||
|
||
return_val = condition_tree( | ||
# Condition tree | ||
query_string = condition_tree( | ||
config, | ||
always_show_buttons=True | ||
) | ||
|
||
st.code(return_val) | ||
|
||
df = df.query(return_val) | ||
st.dataframe(df) | ||
# Filtered dataframe | ||
df = df.query(query_string) |