Question: I have a data set with one row per subject. Some variables include laboratory parameters for blood chemistry, hematology, etc. I also have some flag variables: any = 1 if the subject experienced an adverse event, 0 if not; and ser\_flag = 1 if the subject experienced a serious adverse event, 0 if not.

There doesn't seem to be any difference in the distribution of laboratory parameters between subjects who experienced an adverse event (any=1) and subjects who did not (any = 0). When I do a pair plot of all the lab parameters against each other and color by the any flag, there doesn't seem to be any clustering or separation of subjects.

However, when I do the same pair plot and color by ser\_flag - I notice that the 20 subjects who experienced a serious adverse events seem to be clustered together in many of the plots.

What test (if any) can I use to determine if these clusters I think I am seeing are occurring randomly, by chance...or if they statistically significant?

Answer: 
Let's say you have the following data:

```
import pandas as pd
import numpy as np
df = pd.DataFrame({'values': ['1', '2', '3', '4', '5', '6'],
                  'month1': ['January', 'March', np.nan, np.nan, np.nan, np.nan],
                  'month2': [np.nan, np.nan, 'February', 'April', np.nan, np.nan],
                  'month3': [np.nan, np.nan, np.nan, np.nan, 'May', 'October']})

  values   month1    month2   month3
0      1  January       NaN      NaN
1      2    March       NaN      NaN
2      3      NaN  February      NaN
3      4      NaN     April      NaN
4      5      NaN       NaN      May
5      6      NaN       NaN  October

```

**You can use the following solution:**

```
df['month']=np.nan
for month in [col for col in df.columns if 'month' in col]:
    df['month'].fillna(df[month],inplace=True)

```

It first creates an empty column named "month" with NaN values, and you fill the NaN with the values from the "monthX" columns, concretely it gives you:

```
  values   month1    month2   month3     month
0      1  January       NaN      NaN   January
1      2    March       NaN      NaN     March
2      3      NaN  February      NaN  February
3      4      NaN     April      NaN     April
4      5      NaN       NaN      May       May
5      6      NaN       NaN  October   October

```
You should be able to compare to `"nan"` to get the required behavior:

```
df["month"] = df["month1"]

for month in ["month2", "month3"]:
    mask = df[month].values != "nan"
    df["month"][mask] = df[month][mask]

```