That question might sounds completely stupid but since I have 0 experience with such problem, then I believe it might be worth trying to ask.
The situation that I am facing is that I have multiple functions, and each of them calls one dataframe, and then creates several more dataframes to perform some operations. Yes, I could utilize perhaps OOP, however I don't think that would makes things more readable for my specific case.
The code bellow is an example that I made that could be interesting to visualize what I mean, it does not really has any purpose other than illustrate the problem. Naturally the situation that I am facing is more complicated and involves way more dataframes, that why attributing a variable to each partitioned dataframe and using it as argument to the function is not an option.
dfdata = pd.DataFrame({'Column A': [300,300,450,500,500,750,600,300, 150],'Column B': [1,1,0,1,0,1,0,0,1],'Column C': ['R','C','R','C','Q','C','R','Z','Z']})
def foo1(df):
df_1 = df.loc[df['Column B'] == 1]
df_0 =df.loc[df['Column B'] == 0]
df_x = df_1['Column B']*2
return df_x
def foo2(df):
df_1 = df.loc[df['Column B'] == 1]
df_0 =df.loc[df['Column B'] == 0]
df_y = df_0['Column B']*2
return df_y
def foo3(df):
df_1 = df.loc[df['Column B'] == 1]
df_0 =df.loc[df['Column B'] == 0]
df_z = df_1['Column B']*3
return df_z
So, to sum up, any ideas how to makes things less repetitive and smarter without applying OOP?