# !pip install streamlit # !pip install pandas import pandas as pd import streamlit as st import base64 import io import base64 # Functions def map_data_to_template(mapping_df, template_df, data_df): # Initialize the final output dataframe with the template columns, filled with NaN final_output_df = pd.DataFrame(columns=template_df.columns) # Prepare a dictionary to hold the mapping from MEDLab to NDA variables variable_mapping = mapping_df.set_index('MEDLab Variable')['NDA Variable'].to_dict() # Iterate over each NDA variable to map the data for nda_var in final_output_df.columns: medlab_vars = [medlab_var for medlab_var, nda_mapped_var in variable_mapping.items() if nda_mapped_var == nda_var] # Initialize the column with None final_output_df[nda_var] = [None] * len(data_df) # Go through each potential MEDLab variable until we find one that's present and has data for medlab_var in medlab_vars: if medlab_var in data_df.columns and not data_df[medlab_var].isnull().all(): # If a date column, convert to the specified format if 'date' in medlab_var: final_output_df[nda_var] = pd.to_datetime(data_df[medlab_var], errors='coerce').dt.strftime('%m/%d/%Y') else: final_output_df[nda_var] = data_df[medlab_var] break # Stop checking once we've mapped one return final_output_df # Streamlit app def main(): st.markdown("