I have numerous dataframes and each dataframe has about 100 different chemical compounds and a categorical variable listing the type of material. For example, a smaller version of my datasets would look something like this:
Decane Octanal Material
1 20 Water
2 1 Glass
10 5 Glass
9 4 Water
I am using a linear regression model to regress the chemicals onto the material type. I want to be able to dynamically rename the results dataframe based on which dataset I am using. My code looks like this (where 'feature_cols' are the names of the chemicals):
count=0
dataframe=[]
#loop through the three datasets (In reality I have many more than three)
for dataset in [first, second, third]:
count+=1
for feature in feature_cols:
#define the model and fit it
mod = smf.ols(formula='Q(feature)'+'~material', data=dataset)
res = mod.fit()
#create a dataframe of the pvalues
#I would like to be able to dynamically name pvalues so that when looping through
#the chemicals of the first dataframe it is called 'pvalues_first' and so on.
pvalues=pd.DataFrame(res.pvalues)