I have a data frame, df, with columns "TotalVolume," "Small," "Large," "AllSizes," and "TotalBags" that are correlated. Here, the TotalVolume is the sum of the other four columns.
How do I loop through the data frame columns to see which entries are empty, then fill in the missing value with the value derived from the other columns? For example, if a value from the "AllSizes" column is missing, then the code would loop through the first, the second, the third, then the fourth column, seeing that it is missing a value and uses the fourth command to fill in the missing value.
Expected output:
First, second, third, fourth, fifth commands respectively:
df['TotalVolume'] = df['Small'] + df['Large'] + df['AllSizes'] + df['TotalBags']
df['Small'] = df['TotalVolume'] - df['Large'] - df['AllSizes'] - df['TotalBags']
df['Large'] = df['TotalVolume'] - df['Small'] - df['AllSizes'] - df['TotalBags']
df['AllSizes'] = df['TotalVolume'] - df['Small'] - df['Large'] - df['TotalBags']
df['TotalBags'] = df['TotalVolume'] - df['Small'] - df['Large'] - df['AllSizes']