data_baseutilspandas_to_array

pandas_to_array

data_base.utils.pandas_to_array(pdf, x_component_fun, y_component_fun, value_fun)

Convert a pandas dataframe, in which information is stored linearly to a 2D presentation.

Parameters:
  • pdf (pd.DataFrame) – dataframe to be converted

  • x_component_fun (function) – function to extract the x component

  • y_component_fun (function) – function to extract the y component

  • value_fun (function) – function to extract the value

Returns:

2D representation of the data

Return type:

pd.DataFrame

Example

>>> df
        'bla'
x\_1\_y\_1    10
x\_2\_y\_1    15
x\_3\_y\_1     7
x\_1\_y\_2     2
x\_2\_y\_2     0
x\_3\_y\_2    -1
>>> pandas\_to\_array(
...    pdf,
...    lambda index, values: index.split('\_')[1],
...    lambda index, values: index.split('\_')[-1],
...    lambda index, values: values.bla)
    1    2    3
1    10   15    7
2     2    0   -1