Question: I have some time series data in a pandas dataframe. Many entries have a NaN value, and I'd like to make a matching column storing whether that entry has a NaN value or not, and then replace the NaN values with 0. While replacing the NaN values is easy enough, I can't figure out how to do the first part. If it matters, I already used a pivot operation so column names are tuples. Some of the values in the dataframe are ints and some are floats.

Example input:

```
df = pd.DataFrame(np.array([[5, 7,  np.nan], [np.nan, 8, 9.8], [7, np.nan, 12]]), columns=[('Label', 'A'), ('Label', 'B'), ('Label', 'C')])

                 Label
             A   B   C
2021-03-01   5   7 NaN
2021-03-02 NaN   8 9.8
2021-03-03   7 NaN  12

```

Desired output:

```
                                                        Label
                          A                B                C
            Has data  Value  Has data  Value  Has data  Value
2021-03-01         1      5         1      7         0      0
2021-03-02         0      0         1      8         1     98
2021-03-03         1      7         0      0         1     12

```

Answer: 
### `concat`

```
pd.concat({
    'Has data': df.notna().astype(int),
    'Value': df.fillna(0)
}).unstack(0)

              Label                                    
                  A              B              C      
           Has data Value Has data Value Has data Value
2021-03-01        1   5.0        1   7.0        0   0.0
2021-03-02        0   0.0        1   8.0        1  98.0
2021-03-03        1   7.0        0   0.0        1  12.0

```
```
df = pd.DataFrame(np.array([[5, 7,  np.nan], [np.nan, 8, 98], [7, np.nan, 12]]), columns=['A', 'B', 'C'])

```

[![enter image description here](https://i.stack.imgur.com/8buam.png)](https://i.stack.imgur.com/8buam.png)

```
df['A has data'] = ~(df['A'].isna()).astype(bool)*1

df['B has data'] = ~(df['B'].isna()).astype(bool)*1

df['C has data'] = ~(df['C'].isna()).astype(bool)*1

```

[![enter image description here](https://i.stack.imgur.com/Bjnk3.png)](https://i.stack.imgur.com/Bjnk3.png)

```
df.fillna(0)

```

[![enter image description here](https://i.stack.imgur.com/t40Lz.png)](https://i.stack.imgur.com/t40Lz.png)