Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have a permission to ask a question, You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

ErrorCorner

ErrorCorner Logo ErrorCorner Logo

ErrorCorner Navigation

  • Home
  • Contact Us
  • About Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Contact Us
  • About Us
Home/ Questions/Q 572
Next
Answered
Kenil Vasani
Kenil Vasani

Kenil Vasani

  • 646 Questions
  • 567 Answers
  • 77 Best Answers
  • 26 Points
View Profile
  • 9
Kenil Vasani
Asked: December 14, 20202020-12-14T21:05:31+00:00 2020-12-14T21:05:31+00:00In: Python

AttributeError: ‘float’ object has no attribute ‘split’

  • 9

I am calling this line:

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

This seems to work where row["language_modifiers"] is a word (atlas method, central), but not when it comes up as nan.

I thought my if not isinstance(row["language_modifiers"], float) could catch the time when things come up as nan but not the case.

Background: row["language_modifiers"] is a cell in a tsv file, and comes up as nan when that cell was empty in the tsv being parsed.

csvnanparsingpython
  • 1 1 Answer
  • 15 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    1 Answer

    • Voted
    1. Kenil Vasani

      Kenil Vasani

      • 646 Questions
      • 567 Answers
      • 77 Best Answers
      • 26 Points
      View Profile
      Best Answer
      Kenil Vasani
      2020-12-14T21:02:23+00:00Added an answer on December 14, 2020 at 9:02 pm

      You are right, such errors mostly caused by NaN representing empty cells.
      It is common to filter out such data, before applying your further operations, using this idiom on your dataframe df:

      df_new = df[df['ColumnName'].notnull()]
      

      Alternatively, it may be more handy to use fillna() method to impute (to replace) null values with something default.
      E.g. all null or NaN‘s can be replaced with the average value for its column

      housing['LotArea'] = housing['LotArea'].fillna(housing.mean()['LotArea'])
      

      or can be replaced with a value like empty string “” or another default value

      housing['GarageCond']=housing['GarageCond'].fillna("")
      
      • 2
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp

    You must login to add an answer.

    Forgot Password?

    Sidebar

    Ask A Question
    • Popular
    • Kenil Vasani

      SyntaxError: invalid syntax to repo init in the AOSP code

      • 5 Answers
    • Kenil Vasani

      xlrd.biffh.XLRDError: Excel xlsx file; not supported

      • 3 Answers
    • Kenil Vasani

      Homebrew fails on MacOS Big Sur

      • 3 Answers
    • Kenil Vasani

      runtimeError: package fails to pass a sanity check for numpy ...

      • 3 Answers
    • Kenil Vasani

      Python, Error while installing matplotlib

      • 2 Answers

    Explore

    • Most Answered
    • Most Visited
    • Most Voted
    • Random

    © 2020-2021 ErrorCorner. All Rights Reserved
    by ErrorCorner.com