Skip to content

Commit 1fa9bc5

Browse files
committed
DOC: Adjusted DataFrame.assign docstring
1 parent ef49f88 commit 1fa9bc5

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

pandas/core/frame.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -3220,7 +3220,7 @@ def assign(self, **kwargs):
32203220
32213221
Parameters
32223222
----------
3223-
kwargs : keyword, value pairs
3223+
**kwargs : dict of {str: callable or series}
32243224
The column names are keywords. If the values are
32253225
callable, they are computed on the DataFrame and
32263226
assigned to the new columns. The callable must not
@@ -3230,7 +3230,7 @@ def assign(self, **kwargs):
32303230
32313231
Returns
32323232
-------
3233-
df : DataFrame
3233+
DataFrame
32343234
A new DataFrame with the new columns in addition to
32353235
all the existing columns.
32363236
@@ -3250,8 +3250,9 @@ def assign(self, **kwargs):
32503250
32513251
Examples
32523252
--------
3253-
>>> df = pd.DataFrame({'temp_c': (17.0, 25.0)},
3254-
index=['Portland', 'Berkeley'])
3253+
>>> df = pd.DataFrame({'temp_c': [17.0, 25.0]},
3254+
... index=['Portland', 'Berkeley'])
3255+
>>> df
32553256
temp_c
32563257
Portland 17.0
32573258
Berkeley 25.0
@@ -3264,8 +3265,7 @@ def assign(self, **kwargs):
32643265
32653266
Alternatively, the same behavior can be achieved by directly
32663267
referencing an existing Series or list-like:
3267-
>>> newcol = df['temp_c'] * 9 / 5 + 32
3268-
>>> df.assign(temp_f=newcol)
3268+
>>> df.assign(temp_f=df['temp_c'] * 9 / 5 + 32)
32693269
temp_c temp_f
32703270
Portland 17.0 62.6
32713271
Berkeley 25.0 77.0
@@ -3274,7 +3274,7 @@ def assign(self, **kwargs):
32743274
where one of the columns depends on another one defined within the same
32753275
assign:
32763276
>>> df.assign(temp_f=lambda x: x['temp_c'] * 9 / 5 + 32,
3277-
temp_k=lambda x: (x['temp_f'] + 459.67) * 5 / 9)
3277+
... temp_k=lambda x: (x['temp_f'] + 459.67) * 5 / 9)
32783278
temp_c temp_f temp_k
32793279
Portland 17.0 62.6 290.15
32803280
Berkeley 25.0 77.0 298.15

0 commit comments

Comments
 (0)