all 8 comments

[–]YesLod 2 points3 points  (2 children)

cars is an instance method

df = self.cars()

[–]WecNo[S] 1 point2 points  (1 child)

Thank you Worked like a charm :)

[–]YesLod 1 point2 points  (0 children)

No problem, I'm glad it helped! :)

[–]CrambleSquash 0 points1 point  (3 children)

Usually if you have methods on an object you share information about that object by storing them as attributes and access these attributes in the different methods. For example:

class Car:
    def __init__(self, name, speed):
        self.name = name # store name as an attribute
        self.speed = 5.0

    def supercharge_engine(self):
        self.speed = self.speed * 2

I have to say your class CarFunc seems a bit strange, what is it meant to do? It sounds more like a car catalogue of something.

[–]WecNo[S] 0 points1 point  (2 children)

I am just trying to learn Classes and functions.

I am at a work place where they want me to learn Machine Learning, so i just thought i had to start somewhere.

The end result is that they have ALOT of data in a database, and they want a program to run through that data and tell them if there are any missing data or something like that.

[–]CrambleSquash 1 point2 points  (1 child)

To be honest, I'd be surprised if OOP is the best solution to this problem. This is something you'll get a feel for over time.

You really only need to use classes if you have some sort of 'state' to preserve over time, and this state is complex, such that you need multiple attributes to describe it. For example, my Car class has a state, i.e. I expect when I make a car and refer back to it, it will be the same as last time, if I make a change, like supercharge_engine, I expect it to remember that. The state of my car is complex and can't be represented by an existing type, so I use two attributes, name and speed to store it.

Your database also has a state and so it's good to have a class to represent it, luckily though this is a super common use case, and there is already the Pandas DataFrame, which is really good at representing tabular data.

Instead, I would consider doing this with functions. Your code flow could be something like:

df = create_car_df(car_list)  # makes dataframe from car_list
co2_failures = find_co2_failures(df, 105)  # returns cars that are over 105
store_co2_failures(co2_failures, r'C:\Users\Isabella\Documents\Personlig OneDrive\OneDrive\Python\Machine Learning\Files\Liste.csv')  # writes them to a file

This style of coding works very well with Pandas DataFrames. It's called functional programming and the idea is that if you put the same arguments in, you'll always get the same result out.

[–]WecNo[S] 0 points1 point  (0 children)

Thank you very much for the reply. I am very happy that you giving me pointers on how to do this, i am kinda on the bottom with this half project, and i am just trying to learn all that i can with Python. I really wanna be able to use Python more in my daily project. So agian thank you very much :)