Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
import streamlit as st | |
import pandas as pd | |
def show_single_table(selected_project_index, projects_df, result_df): | |
result_df['crs_3_code_list'] = result_df['crs_3_name'].apply( | |
lambda x: [""] if x is None else (str(x).split(";")[:-1] if str(x).endswith(";") else str(x).split(";")[:-1]) | |
) | |
result_df['crs_5_code_list'] = result_df['crs_5_name'].apply( | |
lambda x: [""] if x is None else (str(x).split(";")[:-1] if str(x).endswith(";") else str(x).split(";")[:-1]) | |
) | |
result_df['sdg_list'] = result_df['sgd_pred_code'].apply( | |
lambda x: [""] if x is None else (str(x).split(";")[:-1] if str(x).endswith(";") else str(x).split(";")) | |
) | |
sel_p_row = projects_df.iloc[[selected_project_index]] | |
sel_p_row['crs_3_code_list'] = sel_p_row['crs_3_name'].apply( | |
lambda x: [""] if x is None else (str(x).split(";")[:-1] if str(x).endswith(";") else str(x).split(";")[:-1]) | |
) | |
sel_p_row['crs_5_code_list'] = sel_p_row['crs_5_name'].apply( | |
lambda x: [""] if x is None else (str(x).split(";")[:-1] if str(x).endswith(";") else str(x).split(";")[:-1]) | |
) | |
sel_p_row['sdg_list'] = sel_p_row['sgd_pred_code'].apply( | |
lambda x: [""] if x is None else (str(x).split(";")[:-1] if str(x).endswith(";") else str(x).split(";")) | |
) | |
st.dataframe( | |
sel_p_row[["iati_id", "title_main", "orga_abbreviation", "client", "description_main", "country_name", "country_flag", "crs_3_code_list", "crs_5_code_list", "sdg_list"]], | |
use_container_width = True, | |
height = 35 + 35 * len(sel_p_row), | |
column_config={ | |
"iati_id": st.column_config.TextColumn( | |
"IATI ID", | |
help="IATI Project ID", | |
disabled=True, | |
width="small" | |
), | |
"orga_abbreviation": st.column_config.TextColumn( | |
"Organization", | |
help="If description not in English, description in other language provided", | |
disabled=True, | |
width="small" | |
), | |
"client": st.column_config.TextColumn( | |
"Client", | |
help="Client organization of customer", | |
disabled=True, | |
width="small" | |
), | |
"title_main": st.column_config.TextColumn( | |
"Title", | |
help="If title not in English, title in other language provided", | |
disabled=True, | |
width="large" | |
), | |
"description_main": st.column_config.TextColumn( | |
"Description", | |
help="If description not in English, description in other language provided", | |
disabled=True, | |
width="large" | |
), | |
"country_name": st.column_config.TextColumn( | |
"Country", | |
help="Country of project", | |
disabled=True, | |
width="small" | |
), | |
"country_flag": st.column_config.ImageColumn( | |
"Flag", | |
help="country flag", | |
width="small" | |
), | |
"sdg_list": st.column_config.ListColumn( | |
"SDG Prediction", | |
help="Prediction of SDG's", | |
width="small" | |
), | |
"crs_3_code_list": st.column_config.ListColumn( | |
"CRS 3", | |
help="CRS 3 code given by organization", | |
width="small" | |
), | |
"crs_5_code_list": st.column_config.ListColumn( | |
"CRS 5", | |
help="CRS 5 code given by organization", | |
width="small" | |
), | |
}, | |
hide_index=True, | |
) | |
if len(result_df) == 0: | |
st.write("No results found!") | |
else: | |
result_df = result_df.reset_index(drop=True) | |
st.write(" ") | |
st.write("----------------------") | |
st.dataframe( | |
result_df[["iati_id", "title_main", "orga_abbreviation", "client", "description_main", "country_name", "country_flag", "sdg_list", "crs_3_code_list", "crs_5_code_list"]], | |
use_container_width = True, | |
height = 35 + 35 * len(result_df), | |
column_config={ | |
"iati_id": st.column_config.TextColumn( | |
"IATI ID", | |
help="IATI Project ID", | |
disabled=True, | |
width="small" | |
), | |
"orga_abbreviation": st.column_config.TextColumn( | |
"Organization", | |
help="If description not in English, description in other language provided", | |
disabled=True, | |
width="small" | |
), | |
"client": st.column_config.TextColumn( | |
"Client", | |
help="Client organization of customer", | |
disabled=True, | |
width="small" | |
), | |
"title_main": st.column_config.TextColumn( | |
"Title", | |
help="If title not in English, title in other language provided", | |
disabled=True, | |
width="large" | |
), | |
"description_main": st.column_config.TextColumn( | |
"Description", | |
help="If description not in English, description in other language provided", | |
disabled=True, | |
width="large" | |
), | |
"country_name": st.column_config.TextColumn( | |
"Country", | |
help="Country of project", | |
disabled=True, | |
width="small" | |
), | |
"country_flag": st.column_config.ImageColumn( | |
"Flag", | |
help="country flag", | |
width="small" | |
), | |
"sdg_list": st.column_config.ListColumn( | |
"SDG Prediction", | |
help="Prediction of SDG's", | |
width="small" | |
), | |
"crs_3_code_list": st.column_config.ListColumn( | |
"CRS 3", | |
help="CRS 3 code given by organization", | |
width="small" | |
), | |
"crs_5_code_list": st.column_config.ListColumn( | |
"CRS 5", | |
help="CRS 5 code given by organization", | |
width="small" | |
), | |
}, | |
hide_index=True, | |
) | |