Added Pandas Is NA and Pandas Drop NA nodes.

This commit is contained in:
HowToSD
2025-02-16 21:42:37 -08:00
parent 24c1450c4c
commit 8a59b2f5c6
6 changed files with 102 additions and 1 deletions
+42
View File
@@ -0,0 +1,42 @@
from typing import Any, Dict
from io import StringIO
import pandas as pd
from .utils import index_to_jsons
class PandasDropNA:
"""
PandasColumns:
A class for droping missing values from a pandas DataFrame.
"""
@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_json": ("STRING", {"multiline": True})
}
}
RETURN_TYPES: tuple = ("STRING",)
FUNCTION: str = "dropna"
CATEGORY: str = "Data Analysis"
def dropna(self, dataframe_json: str) -> tuple:
"""
Returns a DataFrame with missing values removed.
Args:
dataframe_json (str): A JSON string representation of the DataFrame.
Returns:
tuple: A tuple containing a JSON string for the DataFrame.
"""
# Deserialize JSON string to DataFrame
df = pd.read_json(StringIO(dataframe_json))
return (df.dropna().to_json(),)
+42
View File
@@ -0,0 +1,42 @@
from typing import Any, Dict
from io import StringIO
import pandas as pd
from .utils import index_to_jsons
class PandasIsNA:
"""
PandasColumns:
A class for checking a pandas DataFrame for missing values.
"""
@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_json": ("STRING", {"multiline": True})
}
}
RETURN_TYPES: tuple = ("STRING",)
FUNCTION: str = "isna"
CATEGORY: str = "Data Analysis"
def isna(self, dataframe_json: str) -> tuple:
"""
Returns a DataFrame with boolean values with True indicating a missing value.
Args:
dataframe_json (str): A JSON string representation of the DataFrame.
Returns:
tuple: A tuple containing a JSON string for the DataFrame.
"""
# Deserialize JSON string to DataFrame
df = pd.read_json(StringIO(dataframe_json))
return (df.isna().to_json(),)