File tree Expand file tree Collapse file tree 1 file changed +6
-22
lines changed Expand file tree Collapse file tree 1 file changed +6
-22
lines changed Original file line number Diff line number Diff line change @@ -3354,39 +3354,23 @@ def assign(self, **kwargs):
33543354
33553355 Examples
33563356 --------
3357- >>> df = pd.DataFrame({'A': range(1, 11 ),
3358- ... 'B': np.arange(-1.0, 2.0, 0.3 )})
3357+ >>> df = pd.DataFrame({'A': range(1, 3 ),
3358+ ... 'B': np.arange(-1.0, 2.0, 1.5 )})
33593359
33603360 Where the value is a callable, evaluated on `df`:
33613361
33623362 >>> df.assign(ln_A = lambda x: np.log(x.A))
33633363 A B ln_A
3364- 0 1 -1.0 0.000000
3365- 1 2 -0.7 0.693147
3366- 2 3 -0.4 1.098612
3367- 3 4 -0.1 1.386294
3368- 4 5 0.2 1.609438
3369- 5 6 0.5 1.791759
3370- 6 7 0.8 1.945910
3371- 7 8 1.1 2.079442
3372- 8 9 1.4 2.197225
3373- 9 10 1.7 2.302585
3364+ 0 1 -1.0 0.000000
3365+ 1 2 0.5 0.693147
33743366
33753367 Where the value already exists and is inserted:
33763368
33773369 >>> newcol = np.log(df['A'])
33783370 >>> df.assign(ln_A=newcol)
33793371 A B ln_A
3380- 0 1 -1.0 0.000000
3381- 1 2 -0.7 0.693147
3382- 2 3 -0.4 1.098612
3383- 3 4 -0.1 1.386294
3384- 4 5 0.2 1.609438
3385- 5 6 0.5 1.791759
3386- 6 7 0.8 1.945910
3387- 7 8 1.1 2.079442
3388- 8 9 1.4 2.197225
3389- 9 10 1.7 2.302585
3372+ 0 1 -1.0 0.000000
3373+ 1 2 0.5 0.693147
33903374
33913375 Where the keyword arguments depend on each other
33923376
You can’t perform that action at this time.
0 commit comments