Major refactoring to pass DataFrame object without serializing. Almost all nodes were modified for this. Binary operator nodes were added as well.

This commit is contained in:
HowToSD
2025-02-17 22:45:10 -08:00
parent ae59dec59d
commit ec95289880
75 changed files with 1046 additions and 334 deletions
+6 -3
View File
@@ -5,6 +5,9 @@ The objective is to determine which Major League Baseball player has the most hi
Fortunately, the [Lahman Baseball Database](http://seanlahman.com/) contains the necessary data, and CDA simplifies the extraction process. Let's dive in.
**Note**
This tutorial was created using an older version of ComfyUI Data Analysis, so screenshots contain the names of deprecated nodes. Use the node name in text if there is any mismatch between text and screenshots.
# Obtaining data
Our first step is to obtain data.
1. Access http://seanlahman.com/.
@@ -62,7 +65,7 @@ If you see the screenshots, you can see that People data has more than 21000 row
First we want to extract the names from People data. The reason for this is that Batting table contains the ID of the player and not the full name. So we need names defined in the People table. But how do we do this? If we take a look at the screenshot, you do not see full name columns. It looks like the column names are hidden. So we need to first figure out what columns are avaialbe in the People table.
To do so, add a new node **Pandas Columns** and connect it to Load CSV for People.
Then add another node **Pandas Show Text** and connect it to the Pandas Columns node. Press Queue, you should see below.
Then add another node **Pandas Show Index** and connect it to the Pandas Columns node. Press Queue, you should see below.
![Pandas Columns](images/people_columns.png)
@@ -131,12 +134,12 @@ In this final section, we will be fixing the name issue where the names are IDs
![Pandas Join](images/baseball_join1.png)
Drag it next to the **Select Colums** node of the Batting table.
Connect the output of the Head node to the "left_dataframe_json" input of the join node.
Connect the output of the Head node to the "left_dataframe" input of the join node.
2. Connect to the People table
Now drag the join node so that it sits next to the **Select Colums** node of the People table.
Connect the output of the Select Columns node to the "right_dataframe_json" input of the join node. Note that you may need to hover your mouse around the top-left corner of the blank area that contains "right_dataframe_json" to find the connection point.
Connect the output of the Select Columns node to the "right_dataframe" input of the join node. Note that you may need to hover your mouse around the top-left corner of the blank area that contains "right_dataframe" to find the connection point.
![Pandas Join](images/baseball_join2.png)
+44 -7
View File
@@ -1,16 +1,14 @@
# User's Guide
## Basic Concepts
### How DataFrames is passed between nodes
DataFrames are transmitted as JSON strings. When a DataFrame enters a node, it is reconstructed by deserializing the JSON string. Upon exiting, it is serialized back into a JSON string.
Pandas's Index object is also processed the same way. For example, Pandas Columns and Pandas Index node return labels in a serialized Index format.
### How to connect nodes for DataFrame JSON strings
To connect the DataFrame JSON string output from one Pandas node to another, move the wire toward the top-left of the text field. You may need to hover around the corner to find the correct connection point.
### How to connect nodes for DataFrame
To connect the DataFrame output from one Pandas node to another, move the wire toward the top-left of the text field. You may need to hover around the corner to find the correct connection point.
### How to add a node
You can right-click, select **Add Node**, go to **Data Analysis**, and look for the following nodes:
**Note**
This page was initially created using an older version of ComfyUI Data Analysis, so some of screenshots contain the names of deprecated nodes. Use the node name in text if there is any mismatch between text and screenshots.
### List of nodes
**Data loading, creation, saving**
| Node Name | Functionality |
@@ -50,6 +48,7 @@ You can right-click, select **Add Node**, go to **Data Analysis**, and look for
|-------------------------|-------------------------------------|
| **Pandas Show DataFrame** | Display DataFrame contents |
| **Pandas Show Series** | Display Series contents |
| **Pandas Show Index** | Display Index contents |
| **Pandas Show Text** | Display Text |
| **Pandas Summary** | Extract DataFrame statistics |
@@ -72,9 +71,28 @@ You can right-click, select **Add Node**, go to **Data Analysis**, and look for
| **Pandas Sum** | Sum of row values |
| **Pandas Var** | Variance of row values |
**Binary operators for two DataFrames**
| Node Name | Functionality |
|-------------------------|-------------------------------------|
| **Pandas Add** | Add two DataFrames |
| **Pandas Div** | Divide a DataFrame by another DataFrame |
| **Pandas Mul** | Multiply two DataFrames |
| **Pandas Pow** | Raise a DataFrame to the power of another DataFrame |
| **Pandas Sub** | Subtract a DataFrame from another DataFrame |
**Binary operators for a DataFrame and a Series**
| Node Name | Functionality |
|-------------------------|-------------------------------------|
| **Pandas Add Series** | Add a DataFrame and a Series |
| **Pandas Div Series** | Divide a DataFrame by a Series |
| **Pandas Mul Series** | Multiply a DataFrame by a Series |
| **Pandas Pow Series** | Raise a DataFrame to the power of a Series |
| **Pandas Sub Series** | Subtract a Series from another DataFrame |
**Converting to displayable string**
| Node Name | Functionality |
|-------------------------|-------------------------------------|
| **Pandas Index To String** | Convert Index to a displayable string |
| **Pandas Series To String** | Convert Series to a displayable string |
| **Pandas To String** | Convert DataFrame to a displayable string |
@@ -245,6 +263,25 @@ coconut
```
In this case, both apple and coconut are the mode.
## Binary operators for DataFrames and Series
For binary operation for two DataFrames, you can use below operators:
| Node Name | Functionality |
|-------------------------|-------------------------------------|
| **Pandas Add** | Add two DataFrames |
| **Pandas Div** | Divide a DataFrame by another DataFrame |
| **Pandas Mul** | Multiply two DataFrames |
| **Pandas Pow** | Raise a DataFrame to the power of another DataFrame |
| **Pandas Sub** | Subtract a DataFrame from another DataFrame |
For binary operation for a DataFrame and a Series, you can use below operators:
| Node Name | Functionality |
|-------------------------|-------------------------------------|
| **Pandas Add Series** | Add a DataFrame and a Series |
| **Pandas Div Series** | Divide a DataFrame by a Series |
| **Pandas Mul Series** | Multiply a DataFrame by a Series |
| **Pandas Pow Series** | Raise a DataFrame to the power of a Series |
| **Pandas Sub Series** | Subtract a Series from another DataFrame |
## Convert DataFrame to a string
Use **Pandas To String**. This node is to convert the DataFrame to a displayable string, and this truncates the data when the data is large. This can be used to display the data content in a text display node (e.g. Show Text node). However, you can use Show DataFrame nodes to display the DataFrame content, so you do not normally need to use this.