← All ivy-nodes
IVYXSTUDIO · IVY NODE
D

Data Frame Creator

ivy.node.data-frame-creator · v0.1.0

ivyx✓

Builds a pandas DataFrame from a list of row objects and returns it with its row count and column names. The frame is a handle for the next node in the same run.

#data#frame#pandas#tabular data#manipulation#processing#table creation#data analysis#data import export

Inputs

FieldTypeDescription
dictionaryrequiredarrayRows as a list of objects, one key per column.

Outputs

FieldTypeDescription
data_framerequiredNot declaredThe pandas DataFrame built from the rows.
row_countrequiredintegerHow many rows the frame has.
columnsrequiredarrayThe frame's column names, in order.

Source

python

# Input preparation
inp = __ivy_ctx__["nodes"][__ivy_node_id__]["input"]
dictionary = inp["dictionary"]

# Compute
import pandas as pd
from typing import List, Dict

class DataFrameCreator:
    """
    A class to create a pandas DataFrame from a list of dictionaries.
    """

    def __init__(self, dictionary: List[Dict]):
        """
        Initialize the DataFrameCreator with the dictionary.

        :param dictionary: A list of dictionaries to be converted into a pandas DataFrame.
        """
        self.dictionary = dictionary

    def create(self) -> pd.DataFrame:
        """
        Create and return a pandas DataFrame from the provided dictionary.

        :return: A pandas DataFrame.
        """
        if not self.dictionary:
            raise ValueError("No dictionary provided to create the DataFrame.")
        
        return pd.DataFrame(self.dictionary)

data_frameCreator = DataFrameCreator(dictionary=dictionary)
data_frame = data_frameCreator.create()


# Output collection (runner reads __ivy_ctx__)
out = __ivy_ctx__["nodes"][__ivy_node_id__]["output"]
out["data_frame"] = data_frame
out["row_count"] = int(len(data_frame))
out["columns"] = [str(c) for c in data_frame.columns]

Tests

Requires: python:3.9

  • two-rows

    Two row objects become a two-row frame with both columns.

  • no-rows

    An empty list is refused rather than turned into an empty frame.