Added Pandas Fill NA Scalar Int/Float nodes.

This commit is contained in:
HowToSD
2025-02-20 14:50:21 -08:00
parent fff4b58abb
commit 4dba94c46e
7 changed files with 137 additions and 1 deletions
+6
View File
@@ -33,6 +33,8 @@ from .modules.pandas_wrapper.pandas_div_series import PandasDivSeries
from .modules.pandas_wrapper.pandas_drop_duplicates import PandasDropDuplicates
from .modules.pandas_wrapper.pandas_dropna import PandasDropNA
from .modules.pandas_wrapper.pandas_exp import PandasExp
from .modules.pandas_wrapper.pandas_fillna_scalar_float import PandasFillNAScalarFloat
from .modules.pandas_wrapper.pandas_fillna_scalar_int import PandasFillNAScalarInt
from .modules.pandas_wrapper.pandas_group_by import PandasGroupBy
from .modules.pandas_wrapper.pandas_head import PandasHead
from .modules.pandas_wrapper.pandas_horizontal_concat import PandasHorizontalConcat
@@ -133,6 +135,8 @@ NODE_CLASS_MAPPINGS: Dict[str, Type[T]] = {
"PandasDropDuplicates": PandasDropDuplicates,
"PandasDropNA": PandasDropNA,
"PandasExp": PandasExp,
"PandasFillNAScalarFloat": PandasFillNAScalarFloat,
"PandasFillNAScalarInt": PandasFillNAScalarInt,
"PandasGroupBy": PandasGroupBy,
"PandasHead": PandasHead,
"PandasHorizontalConcat": PandasHorizontalConcat,
@@ -233,6 +237,8 @@ NODE_DISPLAY_NAME_MAPPINGS: Dict[str, str] = {
"PandasDropDuplicates": "Pandas Drop Duplicates",
"PandasDropNA": "Pandas Drop NA",
"PandasExp": "Pandas Exp",
"PandasFillNAScalarFloat": "Pandas Fill NA Scalar Float",
"PandasFillNAScalarInt": "Pandas Fill NA Scalar Int",
"PandasGroupBy": "Pandas Group By",
"PandasHead": "Pandas Head",
"PandasHorizontalConcat": "Pandas Horizontal Concat",
+2
View File
@@ -38,6 +38,8 @@
| --- | --- |
| [Pandas Drop Duplicates](pandas_drop_duplicates.md) | Drops duplicate rows from a Pandas DataFrame. |
| [Pandas Drop NA](pandas_dropna.md) | Drops missing values from a pandas DataFrame. |
| [Pandas Fill NA Scalar Float](pandas_fillna_scalar_float.md) | Replaces missing values in a Pandas DataFrame with a floating-point number. |
| [Pandas Fill NA Scalar Int](pandas_fillna_scalar_int.md) | Replaces missing values in a Pandas DataFrame with an integer. |
| [Pandas Is NA](pandas_isna.md) | Checks a pandas DataFrame for missing values. |
| [Pandas Replace](pandas_replace.md) | Replaces part or all of a string in each DataFrame cell with a specified string using a wildcard for matching. If you want to remove some characters, then leave the replace_string field blank. |
## Data subset selection
@@ -0,0 +1,20 @@
# Pandas Fill NA Scalar Float
Replaces missing values in a Pandas DataFrame with a floating-point number.
To set the value, use **the CDA Float Create node** to define the floating-point number and connect it to this node's float_scaler input. Alternatively, you can enter the value directly in this node, but it currently supports only one decimal digit.
## Input
| Name | Data type |
|---|---|
| dataframe | DataFrame |
| float_scalar | Float |
## Output
| Data type |
|---|
| DataFrame |
<HR>
Category: Data cleansing
ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.
@@ -0,0 +1,18 @@
# Pandas Fill NA Scalar Int
Replaces missing values in a Pandas DataFrame with an integer.
## Input
| Name | Data type |
|---|---|
| dataframe | DataFrame |
| int_scalar | Int |
## Output
| Data type |
|---|
| DataFrame |
<HR>
Category: Data cleansing
ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.
@@ -0,0 +1,46 @@
from typing import Any, Dict
import pandas as pd
class PandasFillNAScalarFloat:
"""
Pandas Fill NA Scalar Float:
Replaces missing values in a Pandas DataFrame with a floating-point number.
To set the value, use **the CDA Float Create node** to define the floating-point number and connect it to this node's float_scaler input. Alternatively, you can enter the value directly in this node, but it currently supports only one decimal digit.
category: Data cleansing
"""
@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", {}),
"float_scalar": ("FLOAT", {"default": 0.0, "min": -2**31, "max": 2**31})
}
}
RETURN_TYPES: tuple = ("DATAFRAME",)
FUNCTION: str = "f"
CATEGORY: str = "Data Analysis"
def f(self, dataframe: pd.DataFrame, float_scalar: float) -> tuple:
"""
Replaces missing values in a Pandas DataFrame with a floating-point number.
Args:
dataframe (DataFrame): The DataFrame.
float_scalar (DataFrame): The scalar value to replace with.
Returns:
tuple: A tuple containing the DataFrame containing the result.
"""
df_out = dataframe.fillna(float_scalar)
return (df_out,)
@@ -0,0 +1,44 @@
from typing import Any, Dict
import pandas as pd
class PandasFillNAScalarInt:
"""
Pandas Fill NA Scalar Int:
Replaces missing values in a Pandas DataFrame with an integer.
category: Data cleansing
"""
@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", {}),
"int_scalar": ("INT", {"default": 0, "min": -2**31, "max": 2**31})
}
}
RETURN_TYPES: tuple = ("DATAFRAME",)
FUNCTION: str = "f"
CATEGORY: str = "Data Analysis"
def f(self, dataframe: pd.DataFrame, int_scalar: int) -> tuple:
"""
Replaces missing values in a Pandas DataFrame with an integer.
Args:
dataframe (DataFrame): The DataFrame.
int_scalar (DataFrame): The scalar value to replace with.
Returns:
tuple: A tuple containing the DataFrame containing the result.
"""
df_out = dataframe.fillna(int_scalar)
return (df_out,)
+1 -1
View File
@@ -1,7 +1,7 @@
[project]
name = "data-analysis"
description = "Data analysis custom modules for ComfyUI - Use Pandas & Matplotlib within ComfyUI"
version = "1.1.13"
version = "1.1.14"
license = {file = "LICENSE"}
[project.urls]