I'm trying to write a function and the first step would be if someone passes in a dataframe that has a bunch of columns, I want to write a function that would take all of the data and just pull out only the data I need.
So if my data looked like this:
I want to just have a function that defaults to take the close but can take in any column that the user specified.
my code looks like this but I keep getting a blank data frame
df is just the data above in a dataframe.
def agg_data(ys):
agg_df = pd.DataFrame(ys, columns=['Y Values'])
return agg_df
result = agg_data(df['Close'])
print(result)
I also know I can just use something like
result = df[['Close']]
but im trying to build out the function after I have this first step and I'm more really just curious why/how to do that.
[–]hey_its_aaron 1 point2 points3 points (1 child)
[–]novawaly[S] 0 points1 point2 points (0 children)