0
df = pd.read_csv(r'....movie_metadata.csv')
director = df.director_name.tolist() #I kept director names to list
movie = df.movie_title.tolist() 

But problem is director list has some nan values. When i write the code belove;

directorName = input("Please enter director: ")
i = 0
while(i < 5043):
 if "nan" != director[i]:
    if directorName.__eq__(director[i]):
       print (director[i], movie[i])
i = i + 1

But the output is

Sam Raimi The Quick and the Dead  nan Friday Night Lights 
Sam Raimi Drag Me to Hell  nan The Family 
nan Entourage 
nan Trapped 
nan 12 Monkeys 
nan Limitless 
nan The Honeymooners  ...

and so on. I do not want to print nan values and nan values's movies. How can i edit this code?

1 Answers1

1

Try this:

if not math.isnan(director[i]):
# your code
Prakhar Verma
  • 457
  • 3
  • 12