text_plain_output_1.png
import pandas as pd

df_water = pd.read_csv('../input/water-potability/water_potability.csv')

dict_cl_min = {'ph': 6.5, 'Hardness': 151, 'Solids': 0, 'Chloramines': 0, 'Sulfate': 0, 'Conductivity': 0, 'Organic_carbon': 0, 'Trihalomethanes': 0, 'Turbidity': 0}
dict_cl_max = {'ph': 8.5, 'Hardness': 300, 'Solids': 1200, 'Chloramines': 4, 'Sulfate': 250, 'Conductivity': 400, 'Organic_carbon': 10, 'Trihalomethanes': 80, 'Turbidity': 5}
set_cl_primary = {'Chloramines', 'Conductivity', 'Organic_carbon', 'Trihalomethanes', 'Turbidity'}
set_cl_secondary = {'ph', 'Hardness', 'Solids', 'Sulfate'}

df_cl_filter_applied_by_col = pd.DataFrame()
for col, min_val in dict_cl_min.items():
    df_cl_filter_applied_by_col[col] = df_water[col] >= min_val
for col, max_val in dict_cl_max.items():
    df_cl_filter_applied_by_col[col] = df_cl_filter_applied_by_col[col] & (df_water[col] <= max_val)

df_cl_filter_applied_all = df_cl_filter_applied_by_col.all(axis=1)
print('all filters result:', df_cl_filter_applied_all.value_counts(False), sep='\r\n')
df_cl_filter_applied_primary = df_cl_filter_applied_by_col[set_cl_primary].all(axis=1)
print('primary filters result:', df_cl_filter_applied_primary.value_counts(False), sep='\r\n')
df_cl_filter_applied_secondary = df_cl_filter_applied_by_col[set_cl_secondary].all(axis=1)
print('secondary filters result:', df_cl_filter_applied_secondary.value_counts(False), sep='\r\n')
print(df_water[df_cl_filter_applied_primary])