frame Out[6]: bde Utah -0.764764 0.663018 -1.806592 Ohio 0.082226 -0.164653 -0.744252 Texas 0.763119 1.492637 -1.434447 Oregon -0.485245 -0.806335 -0.008397 frame['b'] +=1 frame Out[8]: bde Utah 0.235236 0.663018 -1.806592 Ohio 1.082226 -0.164653 -0.744252 Texas 1.763119 1.492637 -1.434447 Oregon 0.514755 -0.806335 -0.008397
Edit to add:
If this is an arbial function and you really need to apply for a place, you can write a thin wrapper around pandas to handle it. Personally, I canโt imagine a time when it would be critical that you donโt have to use the standard implementation (if, perhaps, you do not write tons of code and cannot worry about writing additional directors, maybe?)
from pandas import DataFrame import numpy as np class MyWrapper(DataFrame): def __init__(self, *args, **kwargs): super(MyWrapper,self).__init__(*args,**kwargs) def myapply(self,label, func): self[label]= super(MyWrapper,self).__getitem__(label).apply(func) df = frame = MyWrapper(np.random.randn(4, 3), columns=list('bde'), index=['Utah', 'Ohio', 'Texas', 'Oregon']) print df df.myapply('b', lambda x: x+1) print df
It gives:
>> bde Utah -0.260549 -0.981025 1.136154 Ohio 0.073732 -0.895937 -0.025134 Texas 0.555507 -1.173679 0.946342 Oregon 1.871728 -0.850992 1.135784 bde Utah 0.739451 -0.981025 1.136154 Ohio 1.073732 -0.895937 -0.025134 Texas 1.555507 -1.173679 0.946342 Oregon 2.871728 -0.850992 1.135784
Obviously this is a very minimal example, hopefully that provides some methods that are interesting to you.
source share