Pandas map column in place

Viewed 16819

I've spent some time googling and didn't find answer to the simple question: how can I map column of Pandas dataframe in-place? Say, I have the following df:

In [67]: frame = pd.DataFrame(np.random.randn(4, 3), columns=list('bde'), index=['Utah', 'Ohio', 'Texas', 'Oregon'])

In [68]: frame
Out[68]: 
               b         d         e
Utah   -1.240032  1.586191 -1.272617
Ohio   -0.161516 -2.169133  0.223268
Texas  -1.921675  0.246167 -0.744242
Oregon  0.371843  2.346133  2.083234

And I want to add 1 to each value of b column. I know that I can do that like that:

In [69]: frame['b'] = frame['b'].map(lambda x: x + 1)

Or like that -- AFAIK there is no difference between map and apply in context of Series (except that map can also accept dict or Series) -- correct me if I'm wrong:

In [71]: frame['b'] = frame['b'].apply(lambda x: x + 1)

But I don't like specifying 'b' twice. Instead, I would like to do something like that:

frame['b'].map(lambda x: x + 1, inplace=True)

Is it possible?

2 Answers
Related