@@ -180,23 +180,31 @@ def get_rows_by_mask(self, mask: Column[Bool]) -> DataFrame:
180
180
"""
181
181
...
182
182
183
- def insert_column (self , loc : int , column : Column [Any ]) -> DataFrame :
183
+ def insert_column (self , column : Column [Any ]) -> DataFrame :
184
184
"""
185
- Insert column into DataFrame at specified location.
185
+ Insert column into DataFrame at rightmost location.
186
186
187
187
The column's name will be used as the label in the resulting dataframe.
188
188
To insert the column with a different name, combine with `Column.rename`,
189
189
e.g.:
190
190
191
- .. code-block :: python
191
+ .. code-block:: python
192
192
193
193
new_column = df.get_column_by_name('a') + 1
194
- df = df.insert(0, new_column.rename('a_plus_1'))
194
+ df = df.insert_column(new_column.rename('a_plus_1'))
195
+
196
+ If you need to insert the column at a different location, combine with
197
+ :meth:`get_columns_by_name`, e.g.:
198
+
199
+ .. code-block:: python
200
+
201
+ new_column = df.get_column_by_name('a') + 1
202
+ new_columns_names = ['a_plus_1'] + df.get_column_names()
203
+ df = df.insert_column(new_column.rename('a_plus_1'))
204
+ df = df.get_columns_by_name(new_column_names)
195
205
196
206
Parameters
197
207
----------
198
- loc : int
199
- Insertion index. Must verify 0 <= loc <= len(columns).
200
208
column : Column
201
209
"""
202
210
...
@@ -235,13 +243,13 @@ def rename_columns(self, mapping: Mapping[str, str]) -> DataFrame:
235
243
"""
236
244
...
237
245
238
- def get_column_names (self ) -> Sequence [str ]:
246
+ def get_column_names (self ) -> list [str ]:
239
247
"""
240
248
Get column names.
241
249
242
250
Returns
243
251
-------
244
- Sequence [str]
252
+ list [str]
245
253
"""
246
254
...
247
255
0 commit comments