Added Pandas Fill NA Scalar Int/Float nodes.
This commit is contained in:
@@ -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,)
|
||||
Reference in New Issue
Block a user