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
filevalues.dropna(inplace=True)orfilevalues = filevalues.dropna()since,dropna()does not remove in original dataframe when you don't specifyinplace=Trueinstead it returnsdataframewith with NA entries dropped. - studentfilevalues.dropna(how='any',inplace=True)? - studentfilevalues[filevalues.isnull()]? - student