File size: 4,032 Bytes
30b11c6 6498440 f144f21 026a3b5 30b11c6 f144f21 026a3b5 f144f21 026a3b5 f144f21 7148cbd f144f21 026a3b5 5251d02 026a3b5 f144f21 5251d02 026a3b5 6498440 f144f21 026a3b5 f144f21 026a3b5 f144f21 7148cbd 026a3b5 f144f21 7148cbd f144f21 7148cbd f144f21 026a3b5 7148cbd f144f21 |
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 |
import streamlit as st
from PIL import Image
import os
import pandas as pd
@st.cache
def load_data():
df_ind = pd.read_csv("data/df_individuals_score.csv", index_col=[0])
df_ind = df_ind.drop("region_code", axis=1)
df_ind["productive_year"] = df_ind["productive_year"].astype(int)
df_ind["individual_wikidata_id"] = "https://www.wikidata.org/wiki/" + df_ind[
"individual_wikidata_id"
].astype(str)
df_ind = df_ind[df_ind["productive_year"] <= 1800]
return df_ind
df_ind = load_data()
st.title("Our History in Data")
# Set the global index path
global_index_path = "data/immaterial_index/figures_trends_R/results"
global_index_path_per_capita = (
"data/immaterial_index/figures_trends_R/results_per_capita"
)
unseen_index_path = (
"data/immaterial_index/figures_trends_R/figures_unseen/results_unseen"
)
unseen_capita_index_path = (
"data/immaterial_index/figures_trends_R/figures_unseen/results_unseen/per_capita"
)
population_path = "data/population"
maps_path = "data/map_figures"
from region_list import region_list
index_paths = {}
for region_key in region_list:
# Create the index paths for the current region
index_paths[region_key] = {
"map": f"{maps_path}/map_{region_key}.png",
"global_index": f"{global_index_path}/{region_key}.png",
"global_index_per_capita": f"{global_index_path_per_capita}/{region_key}.png",
"unseen_index": f"{unseen_index_path}/{region_key}.png",
"unseen_index_capita": f"{unseen_capita_index_path}/{region_key}.png",
"population_index": f"{population_path}/{region_key}.png",
}
# Get the region names (keys) from the index_paths dictionary
regions = list(index_paths.keys())
# Allow the user to select a region
selected_region = st.sidebar.selectbox("Region:", regions, index=regions.index("Japan"))
# Display the selected region's images vertically
if selected_region in index_paths:
df = df_ind[df_ind["region_name"] == selected_region]
df["productive_year"] = round(df["productive_year"], 0)
df = df.drop(["region_name", "decade"], axis=1)
df = df[
[
"individual_name",
"productive_year",
"score",
"individual_wikidata_id" "",
]
]
df = df.sort_values("score", ascending=False)
df = df.rename(columns={"score": "Number of Catalogs"})
df = df.reset_index(drop=True)
st.dataframe(df)
st.write(f"Number of Cultural producers active before 1800: {len(df)}")
for key, path in index_paths[selected_region].items():
if os.path.exists(path):
if key == "global_index":
st.subheader("Global Index")
st.image(
Image.open(path), caption=key.capitalize(), use_column_width=True
)
elif key == "global_index_per_capita":
st.subheader("Index per capita")
st.image(
Image.open(path), caption=key.capitalize(), use_column_width=True
)
elif key == "unseen_index":
st.subheader("Unsee-Species Index")
st.image(
Image.open(path), caption=key.capitalize(), use_column_width=True
)
elif key == "unseen_index_capita":
st.subheader("Unsee-Species per capita Index")
st.image(
Image.open(path), caption=key.capitalize(), use_column_width=True
)
elif key == "population_index":
st.subheader("Population Index")
st.image(
Image.open(path), caption=key.capitalize(), use_column_width=True
)
elif key == "map":
st.subheader("Maps")
st.sidebar.image(
Image.open(path), caption=key.capitalize(), use_column_width=True
)
else:
st.write(f"File for {key.capitalize()} does not exist.")
|