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

后端 未结 2 484
醉话见心
醉话见心 2021-02-05 16:26

I am calling this line:

lang_modifiers = [keyw.strip() for keyw in row[\"language_modifiers\"].split(\"|\") if not isinstance(row[\"language_modifiers\"], float)         


        
2条回答
  •  天命终不由人
    2021-02-05 17:09

    You might also use df = df.dropna(thresh=n) where n is the tolerance. Meaning, it requires n Non-NA values to not drop the row

    Mind you, this approach will remove the row

    For example: If you have a dataframe with 5 columns, df.dropna(thresh=5) would drop any row that does not have 5 valid, or non-Na values.

    In your case you might only want to keep valid rows; if so, you can set the threshold to the number of columns you have.

    pandas documentation on dropna

提交回复
热议问题