R with function in python
Question: In `R`, I can use `with(obj, a + b + c + d)` instead of `obj$a + obj$b + obj$c
+ obj$d`, where `obj` can be a `list` or `data.frame`.

Is there any similar function for `dict`, `pandas.Series`, `pandas.DataFrame`
in python?


Answer: Not really. R and Python have pretty different philosophies when it comes to
this kind of thing--in R it's possible to write a function which parses the
entire syntax of its arguments before they are evaluated, whereas in Python
it's not. So in Python, this is impossible:

    
    
    df = pd.DataFrame({'a':[1,2],'b':[3,4],'c':[5,6],'d':[7,8]})
    with(df, a + b + c)
    

However, this works:

    
    
    sum(map(df.get, ('a','b','c'))) # gives Series([9,12])
    

If you wanted to apply other chained operations, you could implement support
for something like this:

    
    
    def chain(op, df, name, *names):
        res = df[name]
        while names:
            res = op(res, df[names[0]])
            names = names[1:]
        return res
    

Then you can do this:

    
    
    from operator import div
    chain(div, df, 'a', 'b', 'c')
    

