1

I have a row Languages that might contain nan values, this is a snippet of how the csv file is loaded

df = pd.read_csv(filename_and_path)

for _, row in df.iterrows():
    if row['Languages'].isnull():
        #split by / or ,
        print(row['Languages'])
        languages = list(row['Languages'].split('/').split(','))

and one row in the csv printout in pandas

City                         NaN
Hm PO Box                    NaN
City 2                       NaN
Tel                          NaN
Fax                          NaN
E-mail                       NaN
Languages                    NaN

since i want to process text in languages but it throws a nan error

In [2]: from guides.pandas_import import process_file

In [3]: process_file()
nan
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-029c48606bfe> in <module>
----> 1 process_file()

~/code/kpsga/guides/pandas_import.py in process_file(filename_and_path)
    42             #split by / or ,
    43             print(row['Languages'])
---> 44             languages = list(row['Languages'].split('/').split(','))
    45             languages = [x.lstrip() for x in languages]
    46 

AttributeError: 'float' object has no attribute 'split'

tried checking using isnull and it didn't work

In [1]: from guides.pandas_import import process_file

In [2]: process_file()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-029c48606bfe> in <module>
----> 1 process_file()

~/code/kpsga/guides/pandas_import.py in process_file(filename_and_path)
    39         guide.email = row['E-mail']
    40 
---> 41         if row['Languages'].isnull():
    42             #split by / or ,
    43             print(row['Languages'])

AttributeError: 'float' object has no attribute 'isnull'

is there a way to check it is a nan value possibly by loading the file to recognize them

Sam B.
  • 2,703
  • 8
  • 40
  • 78
  • 1
    Btw, there seems also logic problem, if missing values then want split? Maybe you think if not missing value then processing by split. – jezrael Dec 01 '20 at 10:04

0 Answers0