Added Pandas Horizontal Split and Vertical Split nodes.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
from typing import Any, Dict
|
||||
import pandas as pd
|
||||
|
||||
|
||||
class PandasHorizontalSplit:
|
||||
"""
|
||||
Horizontally splits a Pandas DataFrame into two pandas DataFrames.
|
||||
|
||||
category: Transformation
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls) -> Dict[str, Any]:
|
||||
"""
|
||||
Defines the input types for the function.
|
||||
|
||||
Returns:
|
||||
Dict[str, Any]: A dictionary specifying required input types.
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe": ("DATAFRAME", {}),
|
||||
"column_integer_position": ("INT", {"default": 0, "min": -1, "max": 2**31})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("DATAFRAME", "DATAFRAME")
|
||||
RETURN_NAMES: tuple = ("Left DataFrame", "Right DataFrame")
|
||||
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def f(self, dataframe: pd.DataFrame, column_integer_position: int) -> tuple:
|
||||
"""
|
||||
Horizontally splits a Pandas DataFrame into two pandas DataFrames.
|
||||
|
||||
Args:
|
||||
dataframe (pd.DataFrame): The DataFrame to split.
|
||||
column_integer_position (int): The column integer position where the split occurs.
|
||||
The left DataFrame contains columns [0, column_integer_position-1],
|
||||
and the right DataFrame contains columns [column_integer_position, end].
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing the left and right DataFrames.
|
||||
"""
|
||||
df_left = dataframe.iloc[:,:column_integer_position]
|
||||
df_right = dataframe.iloc[:,column_integer_position:]
|
||||
|
||||
return (df_left, df_right)
|
||||
@@ -0,0 +1,49 @@
|
||||
from typing import Any, Dict
|
||||
import pandas as pd
|
||||
|
||||
|
||||
class PandasVerticalSplit:
|
||||
"""
|
||||
Vertically splits a Pandas DataFrame into two pandas DataFrames.
|
||||
|
||||
category: Transformation
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls) -> Dict[str, Any]:
|
||||
"""
|
||||
Defines the input types for the function.
|
||||
|
||||
Returns:
|
||||
Dict[str, Any]: A dictionary specifying required input types.
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe": ("DATAFRAME", {}),
|
||||
"row_integer_position": ("INT", {"default": 0, "min": -1, "max": 2**31})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("DATAFRAME", "DATAFRAME")
|
||||
RETURN_NAMES: tuple = ("Top DataFrame", "Bottom DataFrame")
|
||||
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def f(self, dataframe: pd.DataFrame, row_integer_position: int) -> tuple:
|
||||
"""
|
||||
Vertically splits a Pandas DataFrame into two pandas DataFrames.
|
||||
|
||||
Args:
|
||||
dataframe (pd.DataFrame): The DataFrame to split.
|
||||
row_integer_position (int): The row integer position where the split occurs.
|
||||
The top DataFrame contains rows [0, row_integer_position-1],
|
||||
and the bottom DataFrame contains rows [row_integer_position, end].
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing the top and bottom DataFrames.
|
||||
"""
|
||||
df_top = dataframe.iloc[:row_integer_position]
|
||||
df_bottom = dataframe.iloc[row_integer_position:]
|
||||
|
||||
return (df_top, df_bottom)
|
||||
Reference in New Issue
Block a user