May-30-2020, 11:39 AM
Try following with pandas:
If you want to get also the keys, why not return two dicts?
One dict could hold all ok_values and the other can contain the not_ok_values.
df = pd.DataFrame(columns=list("abcdefgh")) df[["a", "b", "c"]]In the previous question you asked how to get also the keys.
If you want to get also the keys, why not return two dicts?
One dict could hold all ok_values and the other can contain the not_ok_values.
def classify(mapping): """ Return two dicts from mapping. The first dict contains the `ok values` and the second dict contains the `not ok values` """ ok_mapping = {} nok_mapping = {} for key, value in mapping.items(): if 0 < value < 0.1: ok_mapping[key] = value else: nok_mapping[key] = value return ok_mapping, nok_mapping dictOfVals = {1: 0.2, 2: -0.1, 3: 2, 4: 0.1, 5: 0.05} print(classify(dictOfVals))
Output:({5: 0.05}, {1: 0.2, 2: -0.1, 3: 2, 4: 0.1})
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!