ClarkeJ2000
ClarkeJ2000

Reputation: 47

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

my code is

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

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

Upvotes: 0

Views: 160

Answers (1)

Barmar
Barmar

Reputation: 780974

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)

Upvotes: 1

Related Questions