DataFrame module¶
- class Sloth.DataFrame¶
Bases:
FrameThe 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
dtypeGet the data type of the values of the frame.
- extra
- extras
- i
- iloc
- index
- loc
- mask
- reference
shapeGet the shape of the frame.
valuesGet the values of the frame as a numpy array.
- values_
Methods
Cast the values of the frame to the specified type.
Class method to convert pandas dataframe to a sloth frame
iterrowsIterate over the rows of the frame.
plotPlotting function.
Fits the dataframe with a new index.
resampleResample the frame to a specified frequency.
rollingProvide rolling window calculations.
to_numpyConvert the frame to a numpy array.
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)