Added Pandas Create and Pandas Create with Index nodes to create a DataFrame from text
This commit is contained in:
@@ -3,6 +3,8 @@ from .modules.matplotlib.mpl_bar import MPLBar
|
||||
from .modules.matplotlib.mpl_line import MPLLine
|
||||
from .modules.matplotlib.mpl_scatter import MPLScatter
|
||||
from .modules.pandas_wrapper.pandas_columns import PandasColumns
|
||||
from .modules.pandas_wrapper.pandas_create import PandasCreate
|
||||
from .modules.pandas_wrapper.pandas_create_with_index import PandasCreateWithIndex
|
||||
from .modules.pandas_wrapper.pandas_head import PandasHead
|
||||
from .modules.pandas_wrapper.pandas_index import PandasIndex
|
||||
from .modules.pandas_wrapper.pandas_join import PandasJoin
|
||||
@@ -23,6 +25,8 @@ NODE_CLASS_MAPPINGS: Dict[str, Type[T]] = {
|
||||
"MPLLine": MPLLine,
|
||||
"MPLScatter": MPLScatter,
|
||||
"PandasColumns": PandasColumns,
|
||||
"PandasCreate": PandasCreate,
|
||||
"PandasCreateWithIndex": PandasCreateWithIndex,
|
||||
"PandasHead": PandasHead,
|
||||
"PandasIndex": PandasIndex,
|
||||
"PandasJoin": PandasJoin,
|
||||
@@ -46,6 +50,8 @@ NODE_DISPLAY_NAME_MAPPINGS: Dict[str, str] = {
|
||||
"MPLLine": "MPL Line Plot",
|
||||
"MPLScatter": "MPL Scatter Plot",
|
||||
"PandasColumns": "Pandas Columns",
|
||||
"PandasCreate": "Pandas Create",
|
||||
"PandasCreateWithIndex": "Pandas Create with Index",
|
||||
"PandasHead": "Pandas Head",
|
||||
"PandasIndex": "Pandas Index",
|
||||
"PandasJoin": "Pandas Join",
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 105 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 58 KiB |
+14
-5
@@ -15,6 +15,8 @@ You can right-click, select **Add Node**, go to **Data Analysis**, and look for
|
||||
|-------------------------|-------------------------------------|
|
||||
| **Pandas Load CSV** | Load a CSV file |
|
||||
| **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 |
|
||||
| **Pandas Columns** | Extract column labels |
|
||||
| **Pandas Index** | Extract row labels (index) |
|
||||
| **Pandas Select Columns** | Select specific columns from a DataFrame |
|
||||
@@ -23,7 +25,7 @@ You can right-click, select **Add Node**, go to **Data Analysis**, and look for
|
||||
| **Pandas Head** | Extract the first few rows |
|
||||
| **Pandas Show DataFrame** | Display DataFrame contents |
|
||||
| **Pandas Show Text** | Display Text |
|
||||
| **Pandas Summary** | Show DataFrame statistics |
|
||||
| **Pandas Summary** | Extract DataFrame statistics |
|
||||
| **Pandas Sort** | Sort DataFrame by a column |
|
||||
| **Pandas To String** | Convert DataFrame to a string |
|
||||
| **MPL Bar Chart** | Generate a bar chart |
|
||||
@@ -44,11 +46,17 @@ CSV file path is relative to the ComfyUI installation directory unless you speci
|
||||
## Saving data
|
||||
Use **Pandas Save CSV** node to save the DataFrame to a CSV file.
|
||||
|
||||
## Extracting column and row labels
|
||||
Use **Pandas Columns** and **Pandas Index** nodes. As these nodes outputs JSON-serialized Index object, to display the value, use **Pandas Show Text** node as shown below:
|
||||
## Creating DataFrame on the UI
|
||||
Use **Pandas Create** or **Pandas Create with Index** nodes. These nodes display the multiline text area where you can enter the data in CSV format.
|
||||
If the data contains an index column, use **Pandas Create with Index** and specify the index column.
|
||||
|
||||

|
||||
|
||||
## Extracting column and row labels
|
||||
Use **Pandas Columns** and **Pandas Index** nodes. As these nodes output JSON-serialized Index object, to display the value, use **Pandas Show Text** node as shown below:
|
||||
|
||||

|
||||
|
||||
## Selecting columns and rows
|
||||
Use **Pandas Select Columns** for selecting columns, **Pandas Select Rows** to select rows by a filter condition.
|
||||
|
||||
@@ -91,8 +99,9 @@ This node has been copied to display text without requiring the user to install
|
||||
## Displaying DataFrame contents
|
||||
Use **Pandas Show DataFrame** node. When the number of rows is large, Pandas automatically hides middle rows during string conversion, so the display size should be always manageable.
|
||||
|
||||
## Showing Show DataFrame statistics
|
||||
Use **Pandas Summary**.
|
||||
## Extracting DataFrame statistics
|
||||
Use **Pandas Summary** to extract statistics then connect the output to **Pandas Show Text** for display.
|
||||

|
||||
|
||||
## Sorting DataFrame by a column
|
||||
Use **Pandas Sort**.
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{"last_node_id":4,"last_link_id":2,"nodes":[{"id":1,"type":"PandasCreate","pos":[-326.9039306640625,1636.5106201171875],"size":[210,138.73008728027344],"flags":{},"order":0,"mode":0,"inputs":[],"outputs":[{"name":"STRING","type":"STRING","links":[1],"slot_index":0}],"properties":{"Node name for S&R":"PandasCreate"},"widgets_values":["A,B\n1,10\n2,20\n3,30"]},{"id":4,"type":"PandasShowDataFrame","pos":[-64.19639587402344,1834.85595703125],"size":[217.840576171875,134.7733612060547],"flags":{},"order":3,"mode":0,"inputs":[{"name":"dataframe_json","type":"STRING","link":2,"widget":{"name":"dataframe_json"}}],"outputs":[{"name":"STRING","type":"STRING","links":null,"shape":6}],"properties":{"Node name for S&R":"PandasShowDataFrame"},"widgets_values":[""," A B\nUS 1 10\nFrance 2 20\nGermany 3 30"]},{"id":3,"type":"PandasCreateWithIndex","pos":[-324.8951416015625,1834.365478515625],"size":[210,134.33523559570312],"flags":{},"order":1,"mode":0,"inputs":[],"outputs":[{"name":"STRING","type":"STRING","links":[2],"slot_index":0}],"properties":{"Node name for S&R":"PandasCreateWithIndex"},"widgets_values":["index,A,B\nUS,1,10\nFrance,2,20\nGermany,3,30",0]},{"id":2,"type":"PandasShowDataFrame","pos":[-64.8188705444336,1635.102783203125],"size":[216.83184814453125,135.75343322753906],"flags":{},"order":2,"mode":0,"inputs":[{"name":"dataframe_json","type":"STRING","link":1,"widget":{"name":"dataframe_json"}}],"outputs":[{"name":"STRING","type":"STRING","links":null,"shape":6}],"properties":{"Node name for S&R":"PandasShowDataFrame"},"widgets_values":[""," A B\n0 1 10\n1 2 20\n2 3 30"]}],"links":[[1,1,0,2,0,"STRING"],[2,3,0,4,0,"STRING"]],"groups":[],"config":{},"extra":{"ds":{"scale":1.5305009021021516,"offset":[477.1330786503176,-1565.7063254190393]},"node_versions":{"data-analysis":"3e5a6d6efce2f08933edccaf9e1c1e38896df00b"},"ue_links":[]},"version":0.4}
|
||||
@@ -0,0 +1,46 @@
|
||||
from typing import Any, Dict
|
||||
from io import StringIO
|
||||
import pandas as pd
|
||||
|
||||
|
||||
class PandasCreate:
|
||||
"""
|
||||
PandasLoadCSV:
|
||||
A class for creating a pandas DataFrame using values entered in the text field.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls) -> Dict[str, Any]:
|
||||
"""
|
||||
Defines the input types for the `create` function.
|
||||
|
||||
Returns:
|
||||
Dict[str, Any]: A dictionary specifying required input types.
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"data": ("STRING", {"multiline": True}),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
FUNCTION: str = "create"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def create(self, data: str) -> tuple:
|
||||
"""
|
||||
Create a pandas DataFrame using values entered in the text field and converts it to a JSON string.
|
||||
|
||||
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(StringIO(data))
|
||||
|
||||
# Convert DataFrame to JSON
|
||||
result_json = df.to_json()
|
||||
|
||||
return (result_json,)
|
||||
@@ -0,0 +1,49 @@
|
||||
from typing import Any, Dict
|
||||
from io import StringIO
|
||||
import pandas as pd
|
||||
|
||||
|
||||
class PandasCreateWithIndex:
|
||||
"""
|
||||
PandasLoadCSV:
|
||||
A class for creating a pandas DataFrame using values entered in the text field.
|
||||
Input data is assume to have an index.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls) -> Dict[str, Any]:
|
||||
"""
|
||||
Defines the input types for the `create` function.
|
||||
|
||||
Returns:
|
||||
Dict[str, Any]: A dictionary specifying required input types.
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"data": ("STRING", {"multiline": True}),
|
||||
"index_col": ("INT", {"default": 0, "min": 0, "max": 10000})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
FUNCTION: str = "create"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def create(self, data: str, index_col: int=0) -> tuple:
|
||||
"""
|
||||
Create a pandas DataFrame using values entered in the text field 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(StringIO(data), 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.6"
|
||||
version = "1.0.7"
|
||||
license = {file = "LICENSE"}
|
||||
|
||||
[project.urls]
|
||||
|
||||
Reference in New Issue
Block a user