Skip to content

Commit c47fd3c

Browse files
committed
DOC: cont's simplified examples in DataFrame.assign docstring
1 parent 3d44884 commit c47fd3c

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

pandas/core/frame.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -3354,24 +3354,23 @@ def assign(self, **kwargs):
33543354
33553355
Examples
33563356
--------
3357-
>>> df = pd.DataFrame([('or', 17.),('ca', 25)],
3358-
index=['portland', 'berkeley'],
3359-
columns=['state', 'temp_c'])
3357+
>>> df = pd.DataFrame({'temp_c': (17.0, 25.0)},
3358+
index=['portland', 'berkeley'])
33603359
33613360
Where the value is a callable, evaluated on `df`:
33623361
33633362
>>> df.assign(temp_f=lambda x: x.temp_c * 9 / 5 + 32)
3364-
state temp_c temp_f
3365-
portland or 17.0 62.6
3366-
berkeley ca 25.0 77.0
3363+
temp_c temp_f
3364+
portland 17.0 62.6
3365+
berkeley 25.0 77.0
33673366
33683367
Where the value already exists and is inserted:
33693368
33703369
>>> newcol = df['temp_c'] * 9 / 5 + 32
33713370
>>> df.assign(temp_f=newcol)
3372-
state temp_c temp_f
3373-
portland or 17.0 62.6
3374-
berkeley ca 25.0 77.0
3371+
temp_c temp_f
3372+
portland 17.0 62.6
3373+
berkeley 25.0 77.0
33753374
33763375
Where the keyword arguments depend on each other
33773376

0 commit comments

Comments
 (0)