rapids/src/features/demographic_features.py

18 lines
852 B
Python
Raw Normal View History

import pandas as pd
pid = snakemake.params["pid"]
requested_features = snakemake.params["features"]
demographic_features = pd.DataFrame(columns=["pid"] + requested_features)
participant_info = pd.read_csv(snakemake.input["participant_info"], parse_dates=["surgery_date", "discharge_date"])
demographic_features.loc[0, "pid"] = pid
if not participant_info.empty:
if "age" in requested_features:
demographic_features.loc[0, "age"] = participant_info.loc[0, "age"]
if "gender" in requested_features:
demographic_features.loc[0, "gender"] = participant_info.loc[0, "gender"]
if "inpatientdays" in requested_features:
demographic_features.loc[0, "inpatientdays"] = (participant_info.loc[0, "discharge_date"] - participant_info.loc[0, "surgery_date"]).days
demographic_features.to_csv(snakemake.output[0], index=False)