Skip to content

DF_2_ORDERED_TRIPLE

Convert a DataFrame DataContainer to an OrderedTriple DataContainer. It takes one dataframe type data and selects 3 different columns to generate the OrderedTriple type. Params: default : DataFrame The input dataframe to which we apply the conversion to. x : int The index of the column that represents the x-axis. y : int The index of the column that represents the y-axis. z : int The index of the column that represents the z-axis. Returns: out : OrderedTriple The OrderedTriple result from the conversion of the input.
Python Code
from flojoy import flojoy, DataFrame, OrderedTriple


@flojoy
def DF_2_ORDERED_TRIPLE(
    default: DataFrame, x: int = 0, y: int = 1, z: int = 2
) -> OrderedTriple:
    """Convert a DataFrame DataContainer to an OrderedTriple DataContainer.

    It takes one dataframe type data and selects 3 different columns to generate the OrderedTriple type.

    Parameters
    ----------
    default : DataFrame
        The input dataframe to which we apply the conversion to.
    x : int
        The index of the column that represents the x-axis.
    y : int
        The index of the column that represents the y-axis.
    z : int
        The index of the column that represents the z-axis.

    Returns
    -------
    OrderedTriple
        The OrderedTriple result from the conversion of the input.
    """

    df = default.m
    if df.shape[1] < 3:
        raise AssertionError(
            f"The DataFrame needs to have a shape greater than 2 in order to be converted to the OrderedTriple type, got: {df.shape[1]}"
        )

    x_list = df.iloc[:, x]
    y_list = df.iloc[:, y]
    z_list = df.iloc[:, z]

    x_numpy = x_list.to_numpy(dtype=object)
    y_numpy = y_list.to_numpy(dtype=object)
    z_numpy = z_list.to_numpy(dtype=object)

    return OrderedTriple(x=x_numpy, y=y_numpy, z=z_numpy)

Find this Flojoy Block on GitHub

Example

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 R_DATASET and DF_2_ORDERED_TRIPLE nodes. The parameters that are used for these nodes, are the following:

R_DATASET : airquality

DF_2_ORDERED_TRIPLE : x=5, y=4, z=3

Here the airquality dataset has 6 columns in total. Using these parameters will generate an OrderedTriple with the columns x, y, and z, which corresponds to how the parameters were set.

We can see the node effect by observing the difference between the two TABLE nodes. In the table showing the OrderedTriple output, columns x and y are shown instead of their previous names, and the column values are different from the previous table, as expected since we select different columns. Then, when comparing the SCATTER3D nodes, we can see that the graphs are different than expected. The first one shows the graph of the 3 first columns, while the one showing the resulting OrderedTriple, uses the 3 last columns.