Skip to content

Commit de61b38

Browse files
committed
DOC: cont'd simplified examples in DataFrame.assign docstring
1 parent 58942fc commit de61b38

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
@@ -3250,24 +3250,23 @@ def assign(self, **kwargs):
32503250
32513251
Examples
32523252
--------
3253-
>>> df = pd.DataFrame([('or', 17.),('ca', 25)],
3254-
index=['portland', 'berkeley'],
3255-
columns=['state', 'temp_c'])
3253+
>>> df = pd.DataFrame({'temp_c': (17.0, 25.0)},
3254+
index=['portland', 'berkeley'])
32563255
32573256
Where the value is a callable, evaluated on `df`:
32583257
32593258
>>> df.assign(temp_f=lambda x: x.temp_c * 9 / 5 + 32)
3260-
state temp_c temp_f
3261-
portland or 17.0 62.6
3262-
berkeley ca 25.0 77.0
3259+
temp_c temp_f
3260+
portland 17.0 62.6
3261+
berkeley 25.0 77.0
32633262
32643263
Where the value already exists and is inserted:
32653264
32663265
>>> newcol = df['temp_c'] * 9 / 5 + 32
32673266
>>> df.assign(temp_f=newcol)
3268-
state temp_c temp_f
3269-
portland or 17.0 62.6
3270-
berkeley ca 25.0 77.0
3267+
temp_c temp_f
3268+
portland 17.0 62.6
3269+
berkeley 25.0 77.0
32713270
32723271
Where the keyword arguments depend on each other
32733272

0 commit comments

Comments
 (0)