Skip to content
Advertisement

Calling an attribute defined in a method from another method in data science (python)

I’m learning object oriented programing in a data science context.

I want to understand what good practice is in terms of writing methods within a class that relate to one another.

When I run my code:

JavaScript

I get the following output (only part of the output is shown due to space constrains):

JavaScript

I am happy with the output generated by each method.

But if I try to call print(data.quality_fun()) without first calling print(data.prepper_fun()), I get an error AttributeError: 'MyData' object has no attribute 'df'.

Being new to objected oriented programming, I am wondering if it is considered good practice to structure things like this, or if there is some other way of doing it.

Thanks for any help!

Advertisement

Answer

Make sure you have the df before you use it.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement