Skip to content

Commit e1eccc2

Browse files
committed
Update example
1 parent b5ee370 commit e1eccc2

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed
Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
1-
import numpy as np
2-
import pandas as pd
31
import streamlit as st
4-
from streamlit_condition_tree import condition_tree, config_from_dataframe
2+
import pandas as pd
53

6-
df = pd.read_csv(
7-
'https://drive.google.com/uc?id=1phaHg9objxK2MwaZmSUZAKQ8kVqlgng4&export=download',
8-
index_col=0,
9-
parse_dates=['Date of birth'],
10-
date_format='%Y-%m-%d')
11-
df['Age'] = ((pd.Timestamp.today() - df['Date of birth']).dt.days / 365).astype(int)
12-
df['Sex'] = pd.Categorical(df['Sex'])
13-
df['Likes tomatoes'] = np.random.randint(2, size=df.shape[0]).astype(bool)
4+
from streamlit_condition_tree import condition_tree, config_from_dataframe
145

15-
st.dataframe(df)
6+
# Initial dataframe
7+
df = pd.DataFrame({
8+
'First Name': ['Georges', 'Alfred'],
9+
'Age': [45, 98],
10+
'Favorite Color': ['Green', 'Red'],
11+
'Like Tomatoes': [True, False]
12+
})
1613

14+
# Basic field configuration from dataframe
1715
config = config_from_dataframe(df)
1816

19-
return_val = condition_tree(
17+
# Condition tree
18+
query_string = condition_tree(
2019
config,
20+
always_show_buttons=True
2121
)
2222

23-
st.code(return_val)
24-
25-
df = df.query(return_val)
26-
st.dataframe(df)
23+
# Filtered dataframe
24+
df = df.query(query_string)

0 commit comments

Comments
 (0)