I am creating new variables by applying lambda functions inside of map() using Python 3.4.
The input sequence to map is a list of dicts. The lambda functions are to be defined in a separate config file. To minimize typing, I wanted to use eval() inside the lambda, like so:
dat = [{'a':1, 'b':2}, {'a':2,'b':1}]
a_transformation = 'a > 1'
temp = map(lambda x: eval(a_transformation,x), dat)
The result is as expected, but it appears each item in the input sequence is changed to the output of global()....
I can do something similar with Pandas without issues:
import pandas
dat = [{'a':1, 'b':2}, {'a':2,'b':1}]
dat_pandas = pandas.DataFrame(a)
a_transformation = 'a > 1'
temp = dat_pandas.eval(a_transformation, engine='python')
But I'd prefer to not have to use Pandas.
Any ideas?
Thanks!