Added Pandas Rename node to rename column label or row label (index). Fixed Pandas As Int node's output which was broken due to v1.1.0 refactoring.
This commit is contained in:
@@ -52,6 +52,7 @@ from .modules.pandas_wrapper.pandas_mul import PandasMul
|
||||
from .modules.pandas_wrapper.pandas_mul_series import PandasMulSeries
|
||||
from .modules.pandas_wrapper.pandas_pow import PandasPow
|
||||
from .modules.pandas_wrapper.pandas_pow_series import PandasPowSeries
|
||||
from .modules.pandas_wrapper.pandas_rename import PandasRename
|
||||
from .modules.pandas_wrapper.pandas_replace import PandasReplace
|
||||
from .modules.pandas_wrapper.pandas_save_csv import PandasSaveCSV
|
||||
from .modules.pandas_wrapper.pandas_save_json import PandasSaveJSON
|
||||
@@ -127,6 +128,7 @@ NODE_CLASS_MAPPINGS: Dict[str, Type[T]] = {
|
||||
"PandasMode": PandasMode,
|
||||
"PandasMul": PandasMul,
|
||||
"PandasMulSeries": PandasMulSeries,
|
||||
"PandasRename": PandasRename,
|
||||
"PandasReplace": PandasReplace,
|
||||
"PandasPow": PandasPow,
|
||||
"PandasPowSeries": PandasPowSeries,
|
||||
@@ -209,6 +211,7 @@ NODE_DISPLAY_NAME_MAPPINGS: Dict[str, str] = {
|
||||
"PandasMulSeries": "Pandas Mul Series",
|
||||
"PandasPow": "Pandas Pow",
|
||||
"PandasPowSeries": "Pandas Pow Series",
|
||||
"PandasRename": "Pandas Rename",
|
||||
"PandasReplace": "Pandas Replace",
|
||||
"PandasSaveCSV": "Pandas Save CSV",
|
||||
"PandasSaveJSON": "Pandas Save JSON",
|
||||
|
||||
@@ -105,6 +105,7 @@
|
||||
| [Pandas Horizontal Concat](pandas_horizontal_concat.md) | Horizontally concatenates two pandas DataFrames. |
|
||||
| [Pandas Horizontal Split](pandas_horizontal_split.md) | Horizontally splits a Pandas DataFrame into two pandas DataFrames. |
|
||||
| [Pandas Join](pandas_join.md) | Merges two pandas DataFrames based on a common column. |
|
||||
| [Pandas Rename](pandas_rename.md) | Renames an index (row label) or a column label. |
|
||||
| [Pandas Sort](pandas_sort.md) | Sorts a pandas DataFrame by a specified column. |
|
||||
| [Pandas Vertical Concat](pandas_vertical_concat.md) | Vertically concatenates two pandas DataFrames. |
|
||||
| [Pandas Vertical Split](pandas_vertical_split.md) | Vertically splits a Pandas DataFrame into two pandas DataFrames. |
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
# Pandas Rename
|
||||
Renames an index (row label) or a column label.
|
||||
|
||||
## Input
|
||||
| Name | Data type |
|
||||
|---|---|
|
||||
| dataframe | DataFrame |
|
||||
| axis | DataFrame |
|
||||
| current_label | String |
|
||||
| new_label | |
|
||||
|
||||
## Output
|
||||
| Data type |
|
||||
|---|
|
||||
| DataFrame |
|
||||
|
||||
<HR>
|
||||
Category: Transformation
|
||||
|
||||
ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.
|
||||
@@ -40,4 +40,4 @@ class PandasAsInt:
|
||||
"""
|
||||
# Convert all values to integer, non-numeric values become NaN
|
||||
df = dataframe.apply(pd.to_numeric, errors='coerce').astype('Int64')
|
||||
return (df.to_json(),)
|
||||
return (df,)
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
from typing import Any, Dict
|
||||
import pandas as pd
|
||||
|
||||
|
||||
class PandasRename:
|
||||
"""
|
||||
Renames an index (row label) or a column label.
|
||||
|
||||
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", {}),
|
||||
"axis": (("columns", "index"),),
|
||||
"current_label": ("STRING", {"default": ""}),
|
||||
"new_label": ("STRING", {"default": ""}),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def f(self, dataframe: pd.DataFrame, axis: str, current_label: str, new_label: str) -> tuple:
|
||||
"""
|
||||
Renames an index (row label) or a column label.
|
||||
|
||||
Args:
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
axis (str): Index (row label) or column label.
|
||||
current_label (str): The current label.
|
||||
new_label (str): The new label.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing a JSON string of the renamed DataFrame.
|
||||
"""
|
||||
if axis=="index":
|
||||
df_out = dataframe.rename(index={current_label:new_label})
|
||||
elif axis=="columns":
|
||||
df_out = dataframe.rename(columns={current_label:new_label})
|
||||
else:
|
||||
raise ValueError("Invalid axis. Only index or columns are supported.")
|
||||
return (df_out,)
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
[project]
|
||||
name = "data-analysis"
|
||||
description = "Data analysis custom modules for ComfyUI - Use Pandas & Matplotlib within ComfyUI"
|
||||
version = "1.1.8"
|
||||
version = "1.1.9"
|
||||
license = {file = "LICENSE"}
|
||||
|
||||
[project.urls]
|
||||
|
||||
Reference in New Issue
Block a user