dropna inplace not working. Can anyone help.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madankarmukta
    Contributor
    • Apr 2008
    • 308

    dropna inplace not working. Can anyone help.

    dropna inplace not working. Can anyone help.
  • hussainmujtaba
    New Member
    • Apr 2020
    • 13

    #2
    Usually when it does not wrok, it usually means that you don't have nan values in data frame .Instead you have empty strings.Just remove them.Check out these data preprocessing steps to know more.
    Last edited by Rabbit; Sep 1 '20, 03:45 PM.

    Comment

    • madankarmukta
      Contributor
      • Apr 2008
      • 308

      #3
      I want to set mean value for all empty string instead of removing them.

      here is the thing.
      df = df.replace(r'^\ s*$', np.NaN, regex=True)

      Thanks
      Thanks

      Comment

      • SioSio
        Contributor
        • Dec 2019
        • 272

        #4
        Is this the code you are looking for?
        Code:
        import pandas as pd
        import numpy as np
        s = pd.Series([2.0, np.nan, 0.5, 1.5, np.nan, 1.0])
        print(s)
        m = s.mean()
        print(m)
        s.fillna(m,inplace=True)
        print(s)

        Comment

        • madankarmukta
          Contributor
          • Apr 2008
          • 308

          #5
          I hardly think mean is suitable for series you have.

          Can you please help to understand what you tried to achieve here for the series.

          Thanks.

          Comment

          • SioSio
            Contributor
            • Dec 2019
            • 272

            #6
            What you want to do is find whitespace in the panda's dataframe, replace those values ​​with NaN, and even remove NaN?
            Code:
            df.replace(r'^\s*$', np.nan, regex=True, inplace=True)
            print(df)
            df.dropna(inplace=True)
            print(df)

            Comment

            Working...