Skip to content

Tag: pandas

Consolidating categories in columns

I have a df with a race column, which has 4 categories. However, I would like to only have three categories by combining the last two categories. This is what my current df looks like: I want to consolidate the race==3 and race ==4 into one value (which would be race ==3). So my new df output would look somet…

pandas df apply condition on multiple columns

I have a df that looks like this: I want to create a new column named promoted from the columns master_feature, epic, and feature: value of promoted will be : master feature if adjacent master_feature column value is not null. feature if adjacent feature column value is not null ,and likewise for epic somethi…

Mapping from a different dataframe

I have a dataset of patients, e.g.: and a dataset of diseases of each patient (by ICD code): How can I flag each patient if he had history of a specific ICD code, desired output: I am currently doing it with iteration but this takes too long…. Answer If need indicators – it means only 0, 1 values …