pydata/pandas — pull request #5343 by jreback (2013-10-26 22:34:45+00:00)
Title: ENH: allow in-line expression assignment with df.eval

This was a relatively easy extension of eval to allow in-line creation/assignment.

Allows one to basically use formulas to do things (pandas conquers excel!!!!)

```
In [11]: df = DataFrame(dict(a = range(5), b = range(5,10)))

In [12]: df
Out[12]:
a b
0 0 5
1 1 6
2 2 7
3 3 8
4 4 9

In [13]: df.eval('c=a+b')

In [14]: df.eval('d=a+b+c')

In [15]: df.eval('a=1')

In [16]: df
Out[16]:
a b c d
0 1 5 5 10
1 1 6 7 14
2 1 7 9 18
3 1 8 11 22
4 1 9 13 26
```

You can do this (this could maybe have a bit better syntax though)
```
In [31]: df = DataFrame(dict(a = range(5), b = range(5,10)))

In [32]: formulas = Series(['c=a+b','d=a*b'],index=['a','b'])

In [33]: df.apply(lambda x: df.eval(formulas[x.name]))
Out[33]:
a None
b None
dtype: object

In [34]: df
Out[34]:
a b c d
0 0 5 5 0
1 1 6 7 6
2 2 7 9 14
3 3 8 11 24
4 4 9 13 36
```