Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Dictionaries – print only part of values

I only want the times that have nan beside them to be stored and printed, without the nan part. currently the output is this.

output

Id just like it so it prints 8:00, 15:00, 16:00, 17:00 for each day

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

my code is

free_times = {}
free_times.update(df3.drop_duplicates())

for key2 in free_times.values():
    print(key2) 

>Solution :

free_times.values() returns the values from the dictionary, not the keys. Use .items() to get both the keys and values, so you can check if it’s nan.

from math import isnan

for key2, value2 in free_times.items():
    if isnan(value2):
        print(key2)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading