I want to iterate over a list with variable names in order to use these variables as input for a function. I think, it is more clear, when I provide the code.
data_low_wind= data.loc[data['Windspeed']<=10]
...#(high_wind and W,S,E have similar characteristic and not important for the problem)
data_N = data.loc[(data['WindDirection'] > 315) & (data['WindDirection'] <= 45)]
...
weather_condition = ['low_wind','high_wind','N','W','S','E']
for i in weather_condition:
if len(data_i) != 0:
Errormeasure_i=table_Errormeasure(data_i,park_size)
This code does not work yet, as the values of weather_condition
are read as strings and are in this way not recognized as addition to the data_
command.
My goal is that the for-loop yields the following:
if len(data_low_wind)!=0:
Errormeasure_low_wind=table_Errormeasure(data_low_wind,park_size)
#(and for the other elements of the list accordingly)
Is this in general a good (acceptable) approach? I read, that it is in general undesireable to change variable names via a for loop.
Another approach I did, was using map(lambda...)
, however this also didnt yield the desired result.
weather_condition = ['low_wind','high_wind','N','W','S','E']
data= map(lambda x: 'data_'+x,weather_condition)
print(data)
[output] <map object at 0x00000180929D2860>
I appreciate any help and clarification of my problem. (I hope, this question is not to much of a duplicate. The other questions did not solve my issue)