Updated question in Edit II
I am running a regression model. For that model, I want to test a large set of values in one specific part of the function and then run the model and all following functions.
E.g.
alpha = ['1', '2', '3']
for a in alpha:
oddsvar = 'odds_all' + a
result = 'result_all' + a
norm_odds = 'norm_odds' + a
pos_norm_odds = 'pos_norm_odds' + a
oddsvar = mba263.odds_ratios(result)['Odds ratios']
norm_odds = numpy.power(oddsvar, std_all)
pos_norm_odds = norm_odds
pos_norm_odds[pos_norm_odds<1]=1/pos_norm_odds[pos_norm_odds<1]
pos_norm_odds.sort_values(ascending=False)
print(pos_norm_odds)
When I first define oddsvar (and the other variables) they just contain a string. I want that string to be used in the rest of the function to either be a variable name or pull data from a different part of my code.
For alpha = 1 the handwritten code would look like this:
odds_all1 = mba263.odds_ratios(result_all1)['Odds ratios']
norm_odds_all1 = numpy.power(odds_all1, std_all)
pos_norm_odds_all1=norm_odds_all1
pos_norm_odds_all1[pos_norm_odds_all1<1]=1/pos_norm_odds_all1[pos_norm_odds_all1<1]
pos_norm_odds_all1.sort_values(ascending=False)
I have been trying (and searching) but so far couldn't find a solution that works for me.
Edit:
Rewording my question: I am trying to define a name in the first half by making
oddsvar = 'odds_all' + a -->> result should be e.g. odds_all1
Then I want to use the new name "odds_all1" and have it be the result of the equation on the right. What I can't figure out in the code is, how to have
oddsvar = mba263.odds_ratios(result)['Odds ratios']
... translated to ...
odds_all1 = mba263.odds_ratios(result_all1)['Odds ratios']
So that after the function has run, I can call the variable "odds_all1" and it gives me the whole list of odds for my logistic regression with alpha = 1.
I see that I can solve the first half with a dictionary (thanks @Teh), however, that approach doesn't seem to work for the argument within the function.
Edit II:
alpha= ['1', '2', '3']
for a in alpha:
d = {} #odds_all dict
e = {a: 'result_all' + a} #result_all dict
f = {} #norm_odds dict
g = {} #pos_norm_odds dict
d['odds_all' + a] = mba263.odds_ratios(e[a])['Odds ratios']
f['norm_odds' + a] = numpy.power(d['odds_all' + a], std_all)
g['pos_norm_odds' + a] = e['norm_odds' + a]
g['pos_norm_odds' + a][g['pos_norm_odds' + a]<1]=1/g['pos_norm_odds' + a][g['pos_norm_odds' + a]<1]
g['pos_norm_odds' + a].sort_values(ascending=False)
print(g)
Thank you for the help so far. With the dict approach I was able to solve the left side of the equation.
However, the "mba263.odds_ratios(e[a])" still yields an error (AttributeError: 'str' object has no attribute 'params'). I have "result_all1" defined as a variable name elsewhere, but combining result_all and the alpha can only be done as a string.
Can I switch it back from being a string to being a name within the dict?