General functions module

Generally useful code goes in this module.

Generally useful math and other functions.

pyanp.general.get_matrix(fname_or_df, sheet=0) → numpy.ndarray[source]

Returns a dataframe from a csv/excel filename (or simply returns the dataframe if it is passed as input

Parameters:fname_or_df – The file name to get as a dataframe, or a dataframe

(in which case that param is returned)

Parameters:sheet – If it is a filename, which sheet to use
Returns:The dataframe
pyanp.general.islist(val)[source]

Simple function to check if a value is list like object

Parameters:val – The object to check its listiness.
Returns:Boolean True/False
pyanp.general.linear_interpolate(xs, ys, x)[source]

Piecewise linear interpolation between a bunch of x and y coordinates.

Parameters:
  • xs – Increasing x values (no dupes)
  • ys – The y values
  • x – The x value to linearly interpolate at
Returns:

if x < xs[0], returns ys[0], if x > xs[-1], returns ys[-1] else linearly interpolates.

pyanp.general.matrix_as_df(matrix: numpy.ndarray, index) → pandas.core.frame.DataFrame[source]

Returns a square numpy.ndarray as a dataframe with given row/col names

Parameters:
  • matrix – The square numpy array
  • index – The names of the rows (which is the same as the name of the columns as a list of strings).
Returns:

The dataframe

pyanp.general.unwrap_list(list_ish)[source]

Takes something that is a list(list(tuple(e1, e2))) and unwraps til we have (e1, e2).

Parameters:list_ish – The list to unwrap
Returns:Unwrapped version of list