I am relatively new to Pandas and Python. I am looking for advice on the quickest way to complete the following task. I am trying to write a code which would be similar to the pd.get_dummies()
command, but generalizes it to more than one column.
I want to select the columns dx1, dx2, and dx3, and return a dummy for whether any of these columns includes a given value.
An example of input data:
In [2]: df
Out[2]:
dx1 dx2 dx3 othervar
0 1 2 3 4
1 1 3 5
2 3 4 2
Output data:
In [2]: df
Out[2]:
dx1 dx2 dx3 othervar dx_any1 dx_any2 dx_any 3 dx_any4
0 1 2 3 4 1 1 1 0
1 1 3 5 1 0 1 0
2 3 4 2 0 0 1 1