Skip to content

MAT_2_DF

Download Flojoy Studio to try this app
Convert a Matrix DataContainer to a DataFrame DataContainer. Params: default : Matrix The input matrix to which we apply the conversion to. Returns: out : DataFrame The dataframe result from the conversion of the input.
Python Code
from numpy import asarray
import pandas as pd
from flojoy import flojoy, Matrix, DataFrame


@flojoy
def MAT_2_DF(default: Matrix) -> DataFrame:
    """Convert a Matrix DataContainer to a DataFrame DataContainer.

    Parameters
    ----------
    default : Matrix
        The input matrix to which we apply the conversion to.

    Returns
    -------
    DataFrame
        The dataframe result from the conversion of the input.
    """

    np_data = default.m
    np_array = asarray(np_data)
    df = pd.DataFrame(np_array)

    return DataFrame(df=df)

Find this Flojoy Block on GitHub

Example App

Having problems with this example app? Join our Discord community and we will help you out!
React Flow mini map

In this example we use the MATRIX node to generate a matrix with 9 rows and 3 columns in the parameters.

With the left LINE node we can see the matrix representation in which each of the 9 colored lines represent one of the row of the matrix and it’s value at each column.

Then we use the MAT_2_DF node to convert the input array from matrix type to a dataframe type.

With the right LINE node we can see the output array of MAT_2_DF. In this graph we can only see 3 lines of different colors since it’s showing the evolution of the 3 columns as we go through their rows which is as expected from a dataframe type of data.