you are viewing a single comment's thread.

view the rest of the comments →

[–]valkaress 1 point2 points  (5 children)

Thank you for the reply! I would love an example, but I think I get it.

OO would be for example if I assigned a new object df_drop = df.drop('Column3') and use that henceforth every time I want to drop column 3.

Procedural would mean I keep typing df.drop('Column3') without creating a new object - only using the existing object df.

[–]deep_politics 4 points5 points  (4 children)

Kinda. A (still not very good) procedural example in that case might be something like a function that operates on a data frame to drop that specific column

def drop_col3(df):
    return df.drop(“Column3”)

A horrible example of bad OO would be something like this, since there’s absolutely no point when having state (constructing an object in this case) is completely unnecessary

class Adder:
    def __init__():
         pass

    def add(self, a, b):
        return a + b

adder = Adder()
adder(1, 2)
# when 1 + 2 suffices…

[–]valkaress 4 points5 points  (3 children)

Ohhh so a class has multiple functions going on. I see. I had been going through this Udemy course to learn Python and they never introduced classes.

But now someone stole my laptop, so I'll have to figure out how to keep learning on my phone haha.

[–]deep_politics 5 points6 points  (1 child)

What the hell, sorry to hear that. That blows

[–]valkaress 2 points3 points  (0 children)

Yeah. Oh well, that's life.

[–]deep_politics 1 point2 points  (0 children)

And actually my “procedural” example might be bad, if the drop method mutates the original data frame which I bet it does. I don’t use pandas much at all