turicreate.SFrameBuilder

class turicreate.SFrameBuilder(column_types, column_names=None, num_segments=1, history_size=10, save_location=None)

An interface to incrementally build an SFrame (row by row). It has some basic features such as appending multiple rows at once, polling the last N rows appended, and a primitive parallel insert interface.

Once closed, the SFrame cannot be “reopened” using this interface.

Parameters:
column_types : list[type]

The column types of the result SFrame. Types must be of the python types that are supported by SFrame (int, float, str, array.array, list, dict, datetime.datetime, image). Column types are strictly enforced while appending.

column_names : list[str], optional

Column names of the result SFrame. If given, length of the list must equal the length of column_types. If not given, names are generated.

num_segments : int, optional

Number of segments that can be written in parallel.

history_size : int, optional

The number of rows to be cached as history. Caches the last history_size rows added with append or append_multiple.

Returns:
out : SFrameBuilder

Examples

>>> from turicreate import SFrameBuilder
>>> sb = SFrameBuilder([int,float,str])
>>> sb.append([1,1.0,"1"])
>>> sb.append_multiple([[2,2.0,"2"],[3,3.0,"3"]])
>>> new_sf = sb.close(); new_sf
Columns:
        X1      int
        X2      float
        X3      str
Rows: 3
Data:
+----+-----+----+
| X1 |  X2 | X3 |
+----+-----+----+
| 1  | 1.0 | 1  |
| 2  | 2.0 | 2  |
| 3  | 3.0 | 3  |
+----+-----+----+
[3 rows x 3 columns]

Methods

SFrameBuilder.append(data[, segment]) Append a single row to an SFrame.
SFrameBuilder.append_multiple(data[, segment]) Append multiple rows to an SFrame.
SFrameBuilder.close() Creates an SFrame from all values that were appended to the SFrameBuilder.
SFrameBuilder.column_names()
SFrameBuilder.column_types()
SFrameBuilder.read_history([num, segment]) Outputs the last num rows that were appended either by append or append_multiple.