Skip to content

Commit d5303b1

Browse files
authored
remove loc from insert_column (#239)
* remove loc from insert_column * fix outdated example
1 parent 77bc66b commit d5303b1

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

spec/API_specification/dataframe_api/dataframe_object.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -180,23 +180,31 @@ def get_rows_by_mask(self, mask: Column[Bool]) -> DataFrame:
180180
"""
181181
...
182182

183-
def insert_column(self, loc: int, column: Column[Any]) -> DataFrame:
183+
def insert_column(self, column: Column[Any]) -> DataFrame:
184184
"""
185-
Insert column into DataFrame at specified location.
185+
Insert column into DataFrame at rightmost location.
186186
187187
The column's name will be used as the label in the resulting dataframe.
188188
To insert the column with a different name, combine with `Column.rename`,
189189
e.g.:
190190
191-
.. code-block :: python
191+
.. code-block:: python
192192
193193
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)
195205
196206
Parameters
197207
----------
198-
loc : int
199-
Insertion index. Must verify 0 <= loc <= len(columns).
200208
column : Column
201209
"""
202210
...
@@ -235,13 +243,13 @@ def rename_columns(self, mapping: Mapping[str, str]) -> DataFrame:
235243
"""
236244
...
237245

238-
def get_column_names(self) -> Sequence[str]:
246+
def get_column_names(self) -> list[str]:
239247
"""
240248
Get column names.
241249
242250
Returns
243251
-------
244-
Sequence[str]
252+
list[str]
245253
"""
246254
...
247255

0 commit comments

Comments
 (0)