-1

I would like to create class to find the missing values but below is my mistakes and how can I fix that please help?

     import pandas as pd
     data={'product':['A','B','C','D'],'sales':[100,None,256,100]}
     data=pd.DataFrame(data=data)

     class Information():
         def __init__(self):
            print('information object created')

         def get_missing_values(self):
            missing_values=data.isnull().sum()
            return missing_values

      class Ml:
            def __init__(self,data):
              print('DataPrep created') 
              self.data=data 
              self._info=Information()

     Ml=Ml(data)
    
    Ml.Information()

enter image description here

2
  • Well, Ml doesn't have an attribute Information; the code only defines the attributes data and _info. Why would you think it does otherwise? Commented Jun 14, 2022 at 14:26
  • are you sure Information should be a class and not a method of Ml? Commented Jun 14, 2022 at 14:46

1 Answer 1

1

You can do something like this.

 import pandas as pd
 data = {'product':['A','B','C','D'],'sales':[100,None,256,100]}
 data = pd.DataFrame(data=data)

 class Information():
     def __init__(self, data):
         print('information object created')
         self.data = data
     def get_missing_values(self):
         missing_values = self.data.isnull().sum()
         return missing_values

 class Ml:
     def __init__(self,data):
         print('DataPrep created') 
         self.data = data 
         self.info = Information(data)

  ml = Ml(data)

  print(ml.info.get_missing_values())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.