samedi 19 octobre 2019

How to use if/else in a dictionary with dataframes?

I have a dictionary of 1000 dataframes, but to simplify this lets assume now 3 dataframes.

d = {'key1': DataFrame, 'key2': DataFrame, 'key3': DataFrame}

All dataframes have the same variables: Distance,Country, Price. I want to identify which key contains a dataframe where the Distance Variable is a string. Perhaps by creating a new dictionary whose keys indicate whether the variable distance is string or not.

I tried using the following code but is not working.

comprobar = {"str_in_values_of_{}".format(k) if v[v.dtypes['Hour']==np.str] in v else ".".format(k): v for k, v in d.items()}

Can someone tell me why is not working?

Thanks a lot!

Aucun commentaire:

Enregistrer un commentaire