Skip to content

Commit 3416959

Browse files
committed
DOC: Updated the DataFrame.assign docstring
1 parent 0828c25 commit 3416959

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

pandas/core/frame.py

+24-23
Original file line numberDiff line numberDiff line change
@@ -3354,38 +3354,39 @@ def assign(self, **kwargs):
33543354
33553355
Examples
33563356
--------
3357-
>>> df = pd.DataFrame({'A': range(1, 11), 'B': np.random.randn(10)})
3357+
>>> df = pd.DataFrame({'A': range(1, 11),
3358+
... 'B':np.arange(-1.0, 2.0, 0.3)})
33583359
33593360
Where the value is a callable, evaluated on `df`:
33603361
33613362
>>> df.assign(ln_A = lambda x: np.log(x.A))
3362-
A B ln_A
3363-
0 1 0.426905 0.000000
3364-
1 2 -0.780949 0.693147
3365-
2 3 -0.418711 1.098612
3366-
3 4 -0.269708 1.386294
3367-
4 5 -0.274002 1.609438
3368-
5 6 -0.500792 1.791759
3369-
6 7 1.649697 1.945910
3370-
7 8 -1.495604 2.079442
3371-
8 9 0.549296 2.197225
3372-
9 10 -0.758542 2.302585
3363+
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
33733374
33743375
Where the value already exists and is inserted:
33753376
33763377
>>> newcol = np.log(df['A'])
33773378
>>> df.assign(ln_A=newcol)
3378-
A B ln_A
3379-
0 1 0.426905 0.000000
3380-
1 2 -0.780949 0.693147
3381-
2 3 -0.418711 1.098612
3382-
3 4 -0.269708 1.386294
3383-
4 5 -0.274002 1.609438
3384-
5 6 -0.500792 1.791759
3385-
6 7 1.649697 1.945910
3386-
7 8 -1.495604 2.079442
3387-
8 9 0.549296 2.197225
3388-
9 10 -0.758542 2.302585
3379+
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
33893390
33903391
Where the keyword arguments depend on each other
33913392

0 commit comments

Comments
 (0)