I'm capturing a value from a primary table to apply as a variable later, using this code:
#capturing value of the month
month = str(DF['COLUMN'].max())[6:7]
#reading the xlsx where I want to look for the number of the month
file = pandas.read_excel('myfile.xlsx', sheet_name='sheet1',engine='openpyxl')
mycolumns= file.columns.values.tolist()
Then I made a loop to use this value as a variable.
for i in mycolumns:
if i == month :
this_month = i
but when I use this value as variable to try to get all the values in this single column, like this:
file.loc[:,f'{this_month}']
I get a key error :/
KeyError:'VariableName'
I tryed to execute as a list, as array and tryed to strip the empty spaces as a result from research, like thisbut nothing work for me. Also tryed to change the type of the month variable of str to int and vice versa. Do u guys have some suggestions?
here's a dump df that follows the same format that mine
data = {'1' : ['50000','70000','90000','872'],
'2' : ['8394' , '83704','94809','02984'],
'3' : ['3664' , '74637','39847','38984']
}
df = pd.DataFrame(data)