Download rwd_code_for_opt.py from jkushwaha/code: direct link, hf CLI and curl.
- Browser
- Download file 1.72 kB
-
https://huggingface.co/jkushwaha/code/resolve/main/rwd_code_for_opt.py
- Command line
-
hf download hf://jkushwaha/code/rwd_code_for_opt.py
-
curl -L -o rwd_code_for_opt.py https://huggingface.co/jkushwaha/code/resolve/main/rwd_code_for_opt.py
1.72 kB
| def date_dict(df, pif_key): | |
| date = df.loc[df['pif_key'].astype(str) == str(pif_key), 'encounter_date'].values[0] | |
| date_insert_dict = { | |
| 'attribute_name': 'report_date', | |
| 'attribute_method': 'cv', | |
| 'attribute_normalized_prediction': '', | |
| 'attribute_prediction': str(date), | |
| 'attribute_version': 'v2_090523', | |
| 'attribute_vocab': '', | |
| 'attribute_code': '', | |
| 'date_of_service': '' | |
| } | |
| return date_insert_dict | |
| def report_date_check(dict_list, df): | |
| col_names = {col['attribute_name'] for col in dict_list} | |
| if 'report_date' not in col_names: | |
| pif_key = next((col['attribute_prediction'] for col in dict_list if col['attribute_name'] == 'pif_key'), None) | |
| if pif_key is not None: | |
| date_insert_dict = date_dict(df, pif_key) | |
| dict_list.append(date_insert_dict) | |
| return dict_list | |
| def json_report_date_insertion(json_data, df): | |
| for biomarker_detail in json_data['patient_level']['biomarkers']['details']: | |
| for attribute in biomarker_detail['attribute']: | |
| attribute_details = attribute['attribute_details'] | |
| attribute['attribute_details'] = report_date_check(attribute_details, df) | |
| return json_data | |
| def dicts_to_dataframe(list_of_dicts): | |
| # Initialize an empty DataFrame | |
| df = pd.DataFrame() | |
| # Iterate through each dictionary in the list | |
| for d in list_of_dicts: | |
| # Convert each dictionary into a DataFrame | |
| temp_df = pd.DataFrame([d]) | |
| # Concatenate the temporary DataFrame with the main DataFrame | |
| df = pd.concat([df, temp_df], ignore_index=True) | |
| # Fill missing values with empty strings | |
| df = df.fillna('') | |
| return df |