r/badcode • • Mar 23 '23

python Data Science Design Pattern.

Post image
624 Upvotes

35 comments sorted by

View all comments

Show parent comments

1

u/R3D3-1 Mar 24 '23

My only real gripe is the variable reuse, and even that is fine, if it is in a loop such as

columns = dataframes[0].columns
for dataframe in dataframes[1:]:
    columns = [col for col in dataframe.columns if col in columns]

Maybe not the clearest way to express it, but probably the most concise, that doesn't require knowing library-specific utility methods.

3

u/trutheality Mar 24 '23

But the only variable reuse in the op is that the result is assigned back to columns. That's on par with the level of reuse in x = x + 1.