I have a master dataframe that has hundreds of key values, it's in the below format:
Key,Val1,Val2
a,1,w
a,2,w
a,3,e
b,1,g
b,2,d
The idea is to create a loop that creates a new dataframe for every unique key value:
Key,Val1,Val2
a,1,w
a,2,w
a,3,e
and perform a function over this dataframe and then create a new dataframe that is a concat of all the new dataframes obtained from unique key values. So if the functions were avg and median over val 2, the output would look like:
a b
avg 1 1
med 2 2
The code I've come up with is, the function dataframe is saved in dffinal:
def regression():
X=Final.iloc[:,7:-1].copy()
y=Final[['Sale Rate']].copy()
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=.2, random_state=0)
sel=f_classif(X_train, y_train)
p_values=pd.Series(sel[0], index=X_train.columns)
p_values=p_values.reset_index()
pd.options.display.float_format = "{:,.2f}".format
return p_values
Final.groupby('Key').agg([regression]).T
Please point out where exactly I might be going wrong, I have no idea how to go about this.
error:
ValueError: no results
Data structure eg : Function to run ANOVA and give F stat values as the output