turicreate.SFrame.add_row_number

SFrame.add_row_number(self, column_name='id', start=0, inplace=False)

Returns an SFrame with a new column that numbers each row sequentially. By default the count starts at 0, but this can be changed to a positive or negative number. The new column will be named with the given column name. An error will be raised if the given column name already exists in the SFrame.

If inplace == False (default) this operation does not modify the current SFrame, returning a new SFrame.

If inplace == True, this operation modifies the current SFrame, returning self.

Parameters:
column_name : str, optional

The name of the new column that will hold the row numbers.

start : int, optional

The number used to start the row number count.

inplace : bool, optional. Defaults to False.

Whether the SFrame is modified in place.

Returns:
out : SFrame

The new SFrame with a column name

Notes

The range of numbers is constrained by a signed 64-bit integer, so beware of overflow if you think the results in the row number column will be greater than 9 quintillion.

Examples

>>> sf = turicreate.SFrame({'a': [1, None, None], 'b': ['a', 'b', None]})
>>> sf.add_row_number()
+----+------+------+
| id |  a   |  b   |
+----+------+------+
| 0  |  1   |  a   |
| 1  | None |  b   |
| 2  | None | None |
+----+------+------+
[3 rows x 3 columns]