starepandas.STAREDataFrame.to_array#

STAREDataFrame.to_array(column, shape=None, pivot=False)#

Converts the ‘column’ to a numpy array.

Either a shape argument has to be provided or the dataframe has to contain a column x and y holding the original array coordinates.

If the dataframe has x/y columns, the column can also be pivoted. I.e. rather than reshaping according to the shape, pivoted along the x/y columns. This may be relevant if the dataframe’s row order has changed.

Parameters:
column: str

column name to be converted to an array

shape: tuple

x and y shape of the array. x*y has to equal the length of the dataframe

pivot: bool

if true, rather than simple reshaping, the dataframe is pivoted along the x and y column

Examples

>>> df = starepandas.STAREDataFrame({'x': [0, 0, 1, 1],
...                                  'y': [1, 0, 0, 1],
...                                  'a': [1, 2, 3, 4]})
>>> df.to_array('a', pivot=False)
array([[1, 2],
       [3, 4]])
>>> df.to_array('a', pivot=True)
array([[2, 1],
       [3, 4]])