@@ -3220,7 +3220,7 @@ def assign(self, **kwargs):
3220
3220
3221
3221
Parameters
3222
3222
----------
3223
- kwargs : keyword, value pairs
3223
+ ** kwargs : dict of {str: callable or series}
3224
3224
The column names are keywords. If the values are
3225
3225
callable, they are computed on the DataFrame and
3226
3226
assigned to the new columns. The callable must not
@@ -3230,7 +3230,7 @@ def assign(self, **kwargs):
3230
3230
3231
3231
Returns
3232
3232
-------
3233
- df : DataFrame
3233
+ DataFrame
3234
3234
A new DataFrame with the new columns in addition to
3235
3235
all the existing columns.
3236
3236
@@ -3250,8 +3250,9 @@ def assign(self, **kwargs):
3250
3250
3251
3251
Examples
3252
3252
--------
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
3255
3256
temp_c
3256
3257
Portland 17.0
3257
3258
Berkeley 25.0
@@ -3264,8 +3265,7 @@ def assign(self, **kwargs):
3264
3265
3265
3266
Alternatively, the same behavior can be achieved by directly
3266
3267
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)
3269
3269
temp_c temp_f
3270
3270
Portland 17.0 62.6
3271
3271
Berkeley 25.0 77.0
@@ -3274,7 +3274,7 @@ def assign(self, **kwargs):
3274
3274
where one of the columns depends on another one defined within the same
3275
3275
assign:
3276
3276
>>> 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)
3278
3278
temp_c temp_f temp_k
3279
3279
Portland 17.0 62.6 290.15
3280
3280
Berkeley 25.0 77.0 298.15
0 commit comments