Added Pandas Load CSV with Index node.
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
ComfyUI-Data-Analysis is a custom module for analyzing data using Pandas and Matplotlib within ComfyUI.
|
||||
|
||||
Nodes include:
|
||||
Here are some of the included nodes:
|
||||
|
||||
- Loading a CSV file as a DataFrame
|
||||
- Saving a DataFrame to a CSV file
|
||||
|
||||
@@ -9,6 +9,7 @@ from .modules.pandas_wrapper.pandas_head import PandasHead
|
||||
from .modules.pandas_wrapper.pandas_index import PandasIndex
|
||||
from .modules.pandas_wrapper.pandas_join import PandasJoin
|
||||
from .modules.pandas_wrapper.pandas_load_csv import PandasLoadCSV
|
||||
from .modules.pandas_wrapper.pandas_load_csv_with_index import PandasLoadCSVWithIndex
|
||||
from .modules.pandas_wrapper.pandas_save_csv import PandasSaveCSV
|
||||
from .modules.pandas_wrapper.pandas_select_columns import PandasSelectColumns
|
||||
from .modules.pandas_wrapper.pandas_select_rows import PandasSelectRows
|
||||
@@ -31,6 +32,7 @@ NODE_CLASS_MAPPINGS: Dict[str, Type[T]] = {
|
||||
"PandasIndex": PandasIndex,
|
||||
"PandasJoin": PandasJoin,
|
||||
"PandasLoadCSV": PandasLoadCSV,
|
||||
"PandasLoadCSVWithIndex": PandasLoadCSVWithIndex,
|
||||
"PandasSaveCSV": PandasSaveCSV,
|
||||
"PandasSelectColumns": PandasSelectColumns,
|
||||
"PandasSelectRows": PandasSelectRows,
|
||||
@@ -56,6 +58,7 @@ NODE_DISPLAY_NAME_MAPPINGS: Dict[str, str] = {
|
||||
"PandasIndex": "Pandas Index",
|
||||
"PandasJoin": "Pandas Join",
|
||||
"PandasLoadCSV": "Pandas Load CSV",
|
||||
"PandasLoadCSVWithIndex": "Pandas Load CSV with Index",
|
||||
"PandasSaveCSV": "Pandas Save CSV",
|
||||
"PandasSelectColumns": "Pandas Select Columns",
|
||||
"PandasSelectRows": "Pandas Select Rows",
|
||||
|
||||
+2
-1
@@ -14,6 +14,7 @@ You can right-click, select **Add Node**, go to **Data Analysis**, and look for
|
||||
| Node Name | Functionality |
|
||||
|-------------------------|-------------------------------------|
|
||||
| **Pandas Load CSV** | Load a CSV file |
|
||||
| **Pandas Load CSV with Index** | Load a CSV file containing index |
|
||||
| **Pandas Save CSV** | Save a DataFrame to a CSV file |
|
||||
| **Pandas Create** | Create a DataFrame from CSV text field |
|
||||
| **Pandas Create with Index** | Create a DataFrame from CSV text field containing index |
|
||||
@@ -37,7 +38,7 @@ A faster way is to double-click the canvas to open the node search dialog.
|
||||
The examples directory contains workflows that load data from an example dataset included in this package. These workflows should give you a good idea about how to use these nodes.
|
||||
|
||||
## Loading data
|
||||
Use **Pandas Load CSV** node to load a CSV.
|
||||
Use **Pandas Load CSV** node to load a CSV, or **Pandas Load CSV with Index** node if the CSV contains an index column.
|
||||

|
||||
|
||||
This will emit the DataFrame in a JSON string.
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
Index,Name,Sales
|
||||
A,Foo,10000
|
||||
B,Bar,20000
|
||||
C,Baz,30000
|
||||
|
@@ -0,0 +1,49 @@
|
||||
from typing import Any, Dict
|
||||
from io import StringIO
|
||||
import pandas as pd
|
||||
|
||||
|
||||
class PandasLoadCSVWithIndex:
|
||||
"""
|
||||
PandasLoadCSV:
|
||||
A class for loading CSV files into a pandas DataFrame.
|
||||
Input data is assume to have an index.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls) -> Dict[str, Any]:
|
||||
"""
|
||||
Defines the input types for the `load_csv` function.
|
||||
|
||||
Returns:
|
||||
Dict[str, Any]: A dictionary specifying required input types.
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"file_path": ("STRING", {"multiline": False}),
|
||||
"index_col": ("INT", {"default": 0, "min": 0, "max": 10000})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
FUNCTION: str = "load_csv"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def load_csv(self, file_path: str, index_col: int=0) -> tuple:
|
||||
"""
|
||||
Loads a CSV file into a pandas DataFrame and converts it to a JSON string.
|
||||
Input data is assume to have an index.
|
||||
|
||||
Args:
|
||||
file_path (str): The path to the CSV file.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing a JSON string representation of the DataFrame.
|
||||
"""
|
||||
# Read CSV file into DataFrame
|
||||
df = pd.read_csv(file_path, index_col=index_col)
|
||||
|
||||
# Convert DataFrame to JSON
|
||||
result_json = df.to_json()
|
||||
|
||||
return (result_json,)
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
[project]
|
||||
name = "data-analysis"
|
||||
description = "Data analysis custom modules for ComfyUI - Use Pandas & Matplotlib within ComfyUI"
|
||||
version = "1.0.7"
|
||||
version = "1.0.8"
|
||||
license = {file = "LICENSE"}
|
||||
|
||||
[project.urls]
|
||||
|
||||
Reference in New Issue
Block a user