<jupyter_start><jupyter_text>Converting O2 flow to FIO2<jupyter_code>ventilation_df['O2'] = ventilation_df['O2'].astype(str).apply(lambda t: t.replace(',', '.'))
ventilation_df['O2'] = ventilation_df['O2'].astype(float)
ventilation_df['O2_unit'].value_counts()
ventilation_df.loc[(ventilation_df['O2_unit'] == '%') & (ventilation_df['FIO2'].isnull()), 'FIO2'] = ventilation_df[(ventilation_df['O2_unit'] == '%') & (ventilation_df['FIO2'].isnull())]['O2']
ventilation_df.loc[(ventilation_df['O2_unit'] == 'L/min') & (ventilation_df['O2'] > 15), 'O2'] = np.nan
ventilation_df.loc[(ventilation_df['O2_unit'] == 'L/min') & (ventilation_df['O2'] < 0), 'O2'] = np.nan

ventilation_df.loc[(ventilation_df['O2_unit'] == 'L/min') & (ventilation_df['O2'].notnull()), 'FIO2'] = 20 + 4 * ventilation_df[(ventilation_df['O2_unit'] == 'L/min') & (ventilation_df['O2'].notnull())]['O2']
ventilation_df.loc[(ventilation_df['O2_unit'] == 'L/min') & (ventilation_df['O2'] == 0), 'FIO2'] = 21

variables_to_drop = ['air', 'air_unit', 'peep', 'peep_unit', 'startingFlow', 'startingFlow_unit',
                     'flow', 'flow_unit', 'temperature', 'temperature_unit',
       'ai', 'ai_unit', 'epap', 'epap_unit', 'ipap', 'ipap_unit', 'slop',
       'slop_unit', 'ti_max', 'ti_max_unit', 'ti_min', 'ti_min_unit',
       'trigger_insp', 'trigger_insp_unit', 'duration', 'duration_unit']
ventilation_df.drop(variables_to_drop, axis=1, inplace=True)
fio2_df = ventilation_df[['patient_admission_id', 'FIO2', 'FIO2_unit', 'datetime']].dropna()
spo2_df = ventilation_df[['patient_admission_id', 'spo2', 'spo2_unit', 'datetime']].dropna()
fio2_df, excluded_fio2_df = restrict_variable_to_possible_ranges(fio2_df, 'FIO2', possible_value_ranges, verbose=True)
spo2_df, excluded_spo2_df = restrict_variable_to_possible_ranges(spo2_df, 'spo2', possible_value_ranges, verbose=True)
fio2_df.describe()
fio2_df['FIO2'].plot.hist(bins=50)
plt.show()
spo2_df['spo2'].plot.hist(bins=50)
plt.show()
spo2_df.describe()
import seaborn as sns
g = sns.displot(x="FIO2", data=fio2_df, kde=True, legend=False)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20825426944971537, 'fraction_numerical': 0.030360531309297913, 'mean_word_length': 8.373333333333333, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '184800', 'license': 'MIT', 'n_tokens_mistral': 895, 'n_tokens_neox': 861, 'n_words': 111, 'path': 'preprocessing/ventilation_preprocessing/ventilation_preprocessing.ipynb', 'repo_name': 'JulianKlug/OPSUM', 'size': '2108'}