DataFrame module

class Sloth.DataFrame

Bases: Frame

The Sloth Dataframe is meant to be a faster version of pandas dataframe. It accomplished this by being a thin wrapper of numpy. Essentially its a numpy matrix with an index and a list of columns corresponding to the the row and columns of the numpy matrix.

Parameters:
valuesnumpy.ndarray[ndims=2]

Matrix to store in the DataFrame

indexarray-like or Index, optional

Index to use for resulting frame. Defaults to RangeIndex if no index is provided.

columnsarray-like or Index, optional

Column labels to use for resulting frame. Defaults to RangeIndex if no columns are provided.

Attributes:
columns
dtype

Get the data type of the values of the frame.

extra
extras
i
iloc
index
loc
mask
reference
shape

Get the shape of the frame.

values

Get the values of the frame as a numpy array.

values_

Methods

astype

Cast the values of the frame to the specified type.

from_pandas

Class method to convert pandas dataframe to a sloth frame

iterrows

Iterate over the rows of the frame.

plot

Plotting function.

reindex

Fits the dataframe with a new index.

resample

Resample the frame to a specified frequency.

rolling

Provide rolling window calculations.

to_numpy

Convert the frame to a numpy array.

to_pandas

Class method to convert sloth dataframe to pandas dataframe

columns
from_pandas()

Class method to convert pandas dataframe to a sloth frame

Parameters:
dataframepandas.DataFrame

pd.DataFrame to convert into a sloth DataFrame

Returns:
DataFrame

The sloth dataframe

Examples

>>> import pandas as pd
>>> df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
>>> sloth_df = DataFrame.from_pandas(df)
reindex()

Fits the dataframe with a new index.

Parameters:
indexnumpy.ndarray

Index to fit the dataframe with.

Returns:
DataFrame

A new DataFrame fitted with the new index.

Examples

>>> df = DataFrame({'A': [1, 2], 'B': [3, 4]})
>>> new_df = df.reindex(np.arange(3))
to_pandas()

Class method to convert sloth dataframe to pandas dataframe

Returns:
pandas.DataFrame

The pandas dataframe

Examples

>>> sloth_df = DataFrame({'A': [1, 2], 'B': [3, 4]})
>>> df = sloth_df.to_pandas()

Methods

DataFrame.astype()

Cast the values of the frame to the specified type.

Parameters:
type_type

Type to cast the values to.

Examples

>>> frame.astype(float)