Skip to content

Commit ddcf3cc

Browse files
committed
DOC: Reduce the number of rows in DataFrame.assign examples
1 parent 9a63b2a commit ddcf3cc

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

pandas/core/frame.py

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3353,39 +3353,23 @@ def assign(self, **kwargs):
33533353
33543354
Examples
33553355
--------
3356-
>>> df = pd.DataFrame({'A': range(1, 11),
3357-
... 'B': np.arange(-1.0, 2.0, 0.3)})
3356+
>>> df = pd.DataFrame({'A': range(1, 3),
3357+
... 'B': np.arange(-1.0, 2.0, 1.5)})
33583358
33593359
Where the value is a callable, evaluated on `df`:
33603360
33613361
>>> df.assign(ln_A = lambda x: np.log(x.A))
33623362
A B ln_A
3363-
0 1 -1.0 0.000000
3364-
1 2 -0.7 0.693147
3365-
2 3 -0.4 1.098612
3366-
3 4 -0.1 1.386294
3367-
4 5 0.2 1.609438
3368-
5 6 0.5 1.791759
3369-
6 7 0.8 1.945910
3370-
7 8 1.1 2.079442
3371-
8 9 1.4 2.197225
3372-
9 10 1.7 2.302585
3363+
0 1 -1.0 0.000000
3364+
1 2 0.5 0.693147
33733365
33743366
Where the value already exists and is inserted:
33753367
33763368
>>> newcol = np.log(df['A'])
33773369
>>> df.assign(ln_A=newcol)
33783370
A B ln_A
3379-
0 1 -1.0 0.000000
3380-
1 2 -0.7 0.693147
3381-
2 3 -0.4 1.098612
3382-
3 4 -0.1 1.386294
3383-
4 5 0.2 1.609438
3384-
5 6 0.5 1.791759
3385-
6 7 0.8 1.945910
3386-
7 8 1.1 2.079442
3387-
8 9 1.4 2.197225
3388-
9 10 1.7 2.302585
3371+
0 1 -1.0 0.000000
3372+
1 2 0.5 0.693147
33893373
33903374
Where the keyword arguments depend on each other
33913375

0 commit comments

Comments
 (0)