Calculations

Diffs

Calculations.diffn(diffcol: str, name: str = 'Diff')

Add a diff column to the main dataframe: calculate the diff from the next value

Parameters:
  • diffcol (str) – column to diff from
  • name (str, optional) – diff column name, defaults to “Diff”
Example:

ds.diffn("Col 1", "New col")

Calculations.diffp(diffcol: str, name: str = 'Diff')

Add a diff column to the main dataframe: calculate the diff from the previous value

Parameters:
  • diffcol (str) – column to diff from
  • name (str, optional) – diff column name, defaults to “Diff”
Example:

ds.diffp("Col 1", "New col")

Calculations.diffm(diffcol: str, name: str = 'Diff', default=nan)

Add a diff column to the main dataframe: calculate the diff from the column mean

Parameters:
  • diffcol (str) – column to diff from
  • name – diff column name, defaults to “Diff”
  • name – str, optional
  • default – column default value, defaults to nan
  • default – optional
Example:

ds.diffm("Col 1", "New col")

Calculations.diffs(col: str, serie: iterable, name: str = 'Diff')

Add a diff column from a serie. The serie is an iterable of the same length than the dataframe

Parameters:
  • col (str) – column to diff
  • serie (iterable) – serie to diff from
  • name – name of the diff col, defaults to “Diff”
  • name – str, optional
Example:

ds.diffs("Col 1", [1, 1, 4], "New col")

Calculations.diffsp(col: str, serie: iterable, name: str = 'Diff')

Add a diff column in percentage from a serie. The serie is an iterable of the same length than the dataframe

Parameters:
  • col (str) – column to diff
  • serie (iterable) – serie to diff from
  • name – name of the diff col, defaults to “Diff”
  • name – str, optional
Example:

ds.diffp("Col 1", [1, 1, 4], "New col")

Group by

Calculations.gmean_(col: str, index_col: bool = True) → Ds

Group by and mean column

Parameters:
  • col (str) – column to group
  • index_col (bool) –
Returns:

a dataswim instance

Return type:

Ds

Example:

ds2 = ds.gmean("Col 1")

Calculations.gsum_(col: str, index_col: bool = True) → Ds

Group by and sum column

Parameters:
  • col (str) – column to group
  • index_col (bool) –
Returns:

a dataswim instance

Return type:

Ds

Example:

ds2 = ds.gsum("Col 1")

Ratio

Calculations.ratio(col: str, ratio_col: str = 'Ratio')

Add a column whith the percentages ratio from a column

Parameters:
  • col (str) – column to calculate ratio from
  • ratio_col – new ratio column name, defaults to “Ratio”
  • ratio_col – str, optional
Example:

ds2 = ds.ratio("Col 1")