Q:

ValueError: cannot convert float NaN to integer after already using dropna()

import pandas as pd   
import csv 
import numpy as np

readfile = pd.read_csv('51.csv')
filevalues= readfile.loc[readfile['Customer'].str.contains('Lam Dep', na=False), 'Jul-18\nQty']
filevalues.replace(" ", "")
filevalues = filevalues.replace(r'^\s*$', np.nan, regex=True) 
filevalues.dropna()
int_series = filevalues.astype(int)
calculated_series = int_series.apply(lambda x: x*(1/1.2))

print(calculated_series)

In my csv files, there are cells with NaNs and empty strings ( or perhaps white spaces) I attempt to get rid of cells with white spaces and drop the NaN values, however I run into the error:
ValueError: cannot convert float NaN to integer

The other methods I have found on stackoverflow have proven to not work for this code.  Any idea of how I can move forward?  This is especially confusing because my code specifies to drop NaNs and then the error states: cannot convert float NaN to integer 

A:

You can try as following:
filevalues = filevalues.replace(" ", "", regex=True)
filevalues.replace("", np.nan, inplace=True) # replace empty string with np.nan
filevalues.dropna(inplace=True) # drop nan values
int_series = filevalues.astype(int) # change type

calculated_series = int_series.apply(lambda x: x*(1/1.2))

print(calculated_series)

