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:
@@ -21,7 +21,7 @@ class CDAJSONCreate:
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "create"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ def common_input_types():
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiscatter": True}),
|
||||
"dataframe": ("STRING", {"multiscatter": True}),
|
||||
"x_column_name": ("STRING", {"default": ""}),
|
||||
"y_column_name": ("STRING", {"default": ""}),
|
||||
"title": ("STRING", {"default": ""}),
|
||||
|
||||
@@ -26,7 +26,7 @@ class MPLBar:
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def bar_chart(self,
|
||||
dataframe_json: str,
|
||||
dataframe: pd.DataFrame,
|
||||
x_column_name: str,
|
||||
y_column_name: str,
|
||||
title: str,
|
||||
@@ -37,7 +37,7 @@ class MPLBar:
|
||||
Generates a bar chart from a pandas DataFrame.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
x_column_name (str): The column name for the x-axis.
|
||||
y_column_name (str): The column name for the y-axis.
|
||||
title (str): The title of the plot.
|
||||
@@ -49,8 +49,8 @@ class MPLBar:
|
||||
Returns:
|
||||
tuple: A tuple containing the image tensor representation of the plot.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
|
||||
df = dataframe
|
||||
|
||||
# Create the plot
|
||||
fig, ax = plt.subplots()
|
||||
|
||||
@@ -26,7 +26,7 @@ class MPLLine:
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def line_plot(self,
|
||||
dataframe_json: str,
|
||||
dataframe: pd.DataFrame,
|
||||
x_column_name: str,
|
||||
y_column_name: str,
|
||||
title: str,
|
||||
@@ -37,7 +37,7 @@ class MPLLine:
|
||||
Generates a line plot from a pandas DataFrame.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
x_column_name (str): The column name for the x-axis.
|
||||
y_column_name (str): The column name for the y-axis.
|
||||
title (str): The title of the plot.
|
||||
@@ -49,8 +49,8 @@ class MPLLine:
|
||||
Returns:
|
||||
tuple: A tuple containing the image tensor representation of the plot.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
|
||||
df = dataframe
|
||||
|
||||
# Create the plot
|
||||
fig, ax = plt.subplots()
|
||||
|
||||
@@ -26,7 +26,7 @@ class MPLScatter:
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def scatter_plot(self,
|
||||
dataframe_json: str,
|
||||
dataframe: pd.DataFrame,
|
||||
x_column_name: str,
|
||||
y_column_name: str,
|
||||
title: str,
|
||||
@@ -37,7 +37,7 @@ class MPLScatter:
|
||||
Generates a scatter plot from a pandas DataFrame.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
x_column_name (str): The column name for the x-axis.
|
||||
y_column_name (str): The column name for the y-axis.
|
||||
title (str): The title of the plot.
|
||||
@@ -49,8 +49,8 @@ class MPLScatter:
|
||||
Returns:
|
||||
tuple: A tuple containing the image tensor representation of the plot.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
|
||||
df = dataframe
|
||||
|
||||
# Create the plot
|
||||
fig, ax = plt.subplots()
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
from typing import Any, Dict
|
||||
import pandas as pd
|
||||
|
||||
|
||||
class PandasAdd:
|
||||
"""
|
||||
PandasAdd:
|
||||
A class for adding two pandas DataFrames.
|
||||
"""
|
||||
|
||||
@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": {
|
||||
"a_dataframe": ("DATAFRAME", {}),
|
||||
"b_dataframe": ("DATAFRAME", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def f(self, a_dataframe: pd.DataFrame, b_dataframe: pd.DataFrame) -> tuple:
|
||||
"""
|
||||
Add two pandas DataFrames.
|
||||
|
||||
Args:
|
||||
a_dataframe (DataFrame): The left DataFrame.
|
||||
b_dataframe (DataFrame): The right DataFrame.
|
||||
on_column_name (str): The name of the column to join on.
|
||||
join_method (str): The type of join to perform ("inner", "left", "right", "outer").
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing the DataFrame containing the result of addition.
|
||||
"""
|
||||
df_out = a_dataframe.add(b_dataframe)
|
||||
return (df_out,)
|
||||
@@ -0,0 +1,43 @@
|
||||
from typing import Any, Dict
|
||||
import pandas as pd
|
||||
|
||||
class PandasAddSeries:
|
||||
"""
|
||||
PandasAdd:
|
||||
A class for adding a Pandas Series to a pandas DataFrames.
|
||||
"""
|
||||
|
||||
@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": {
|
||||
"a_dataframe": ("DATAFRAME", {}),
|
||||
"b_series": ("PDSERIES", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def f(self, a_dataframe: pd.DataFrame, b_series: pd.Series) -> tuple:
|
||||
"""
|
||||
Add two pandas DataFrames.
|
||||
|
||||
Args:
|
||||
a_dataframe (DataFrame): The left DataFrame.
|
||||
b_series (Series): The right Series.
|
||||
on_column_name (str): The name of the column to join on.
|
||||
join_method (str): The type of join to perform ("inner", "left", "right", "outer").
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing the DataFrame containing the result of addition.
|
||||
"""
|
||||
df_out = a_dataframe.add(b_series)
|
||||
return (df_out,)
|
||||
@@ -0,0 +1,42 @@
|
||||
from typing import Any, Dict
|
||||
from io import StringIO
|
||||
import pandas as pd
|
||||
|
||||
|
||||
class PandasAsFloat:
|
||||
"""
|
||||
PandasAsFloat:
|
||||
A class for converting all cells in a pandas DataFrame to float type.
|
||||
"""
|
||||
|
||||
@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", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def f(self, dataframe: pd.DataFrame) -> tuple:
|
||||
"""
|
||||
Converts all cells in the DataFrame to float type.
|
||||
|
||||
Args:
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing the DataFrame with all values as floats.
|
||||
"""
|
||||
# Convert all values to float, non-numeric values become NaN
|
||||
df = dataframe.apply(pd.to_numeric, errors='coerce').astype(float)
|
||||
return (df,)
|
||||
@@ -0,0 +1,42 @@
|
||||
from typing import Any, Dict
|
||||
from io import StringIO
|
||||
import pandas as pd
|
||||
|
||||
|
||||
class PandasAsInt:
|
||||
"""
|
||||
PandasAsInt:
|
||||
A class for converting all cells in a pandas DataFrame to integer type.
|
||||
"""
|
||||
|
||||
@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", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def f(self, dataframe: pd.DataFrame) -> tuple:
|
||||
"""
|
||||
Converts all cells in the DataFrame to integer type.
|
||||
|
||||
Args:
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing the DataFrame with all values as integers.
|
||||
"""
|
||||
# Convert all values to integer, non-numeric values become NaN
|
||||
df = dataframe.apply(pd.to_numeric, errors='coerce').astype('Int64')
|
||||
return (df.to_json(),)
|
||||
@@ -0,0 +1,41 @@
|
||||
from typing import Any, Dict
|
||||
import pandas as pd
|
||||
|
||||
|
||||
class PandasAsString:
|
||||
"""
|
||||
PandasAsString:
|
||||
A class for converting all cells in a pandas DataFrame to string type.
|
||||
"""
|
||||
|
||||
@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", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "convert_to_string"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def convert_to_string(self, dataframe: pd.DataFrame) -> tuple:
|
||||
"""
|
||||
Converts all cells in the DataFrame to string type.
|
||||
|
||||
Args:
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing the DataFrame with all values as strings.
|
||||
"""
|
||||
# Convert all values to string
|
||||
df = dataframe.astype(str)
|
||||
return (df,)
|
||||
@@ -1,14 +1,13 @@
|
||||
from typing import Any, Dict
|
||||
from io import StringIO
|
||||
import pandas as pd
|
||||
from .utils import index_to_jsons
|
||||
|
||||
|
||||
class PandasColumns:
|
||||
"""
|
||||
PandasColumns:
|
||||
A class for retrieving the column labels of a pandas DataFrame.
|
||||
"""
|
||||
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls) -> Dict[str, Any]:
|
||||
"""
|
||||
@@ -19,25 +18,23 @@ class PandasColumns:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiline": True})
|
||||
"dataframe": ("DATAFRAME", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("PDINDEX",)
|
||||
FUNCTION: str = "columns"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def columns(self, dataframe_json: str) -> tuple:
|
||||
def columns(self, dataframe: pd.DataFrame) -> tuple:
|
||||
"""
|
||||
Returns the column labels of a pandas DataFrame.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing a JSON string for the serialized pandas.Index containing columns.
|
||||
tuple: A tuple containing a pandas.Index for columns.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
columns = df.columns
|
||||
return (index_to_jsons(columns),)
|
||||
columns = dataframe.columns
|
||||
return (columns,)
|
||||
|
||||
@@ -19,24 +19,23 @@ class PandasCount:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiline": True})
|
||||
"dataframe": ("DATAFRAME", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("PDSERIES",)
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def f(self, dataframe_json: str) -> tuple:
|
||||
def f(self, dataframe: pd.DataFrame) -> tuple:
|
||||
"""
|
||||
Returns a Series with count for each column.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing a JSON string for the Series.
|
||||
tuple: A tuple containing the Series.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
return (series_to_jsons(df.count()),)
|
||||
df = dataframe
|
||||
return (df.count(),)
|
||||
|
||||
@@ -23,7 +23,7 @@ class PandasCreate:
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "create"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
@@ -39,8 +39,4 @@ class PandasCreate:
|
||||
"""
|
||||
# Read CSV file into DataFrame
|
||||
df = pd.read_csv(StringIO(data))
|
||||
|
||||
# Convert DataFrame to JSON
|
||||
result_json = df.to_json()
|
||||
|
||||
return (result_json,)
|
||||
return (df,)
|
||||
|
||||
@@ -25,7 +25,7 @@ class PandasCreateWithIndex:
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "create"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
@@ -43,8 +43,4 @@ class PandasCreateWithIndex:
|
||||
"""
|
||||
# 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,)
|
||||
return (df,)
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
from typing import Any, Dict
|
||||
from io import StringIO
|
||||
import pandas as pd
|
||||
|
||||
|
||||
class PandasDiv:
|
||||
"""
|
||||
PandasDiv:
|
||||
A class for dividing two pandas DataFrames.
|
||||
"""
|
||||
|
||||
@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": {
|
||||
"a_dataframe": ("DATAFRAME", {}),
|
||||
"b_dataframe": ("DATAFRAME", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def f(self, a_dataframe: pd.DataFrame, b_dataframe: pd.DataFrame) -> tuple:
|
||||
"""
|
||||
Divide two pandas DataFrames.
|
||||
|
||||
Args:
|
||||
a_dataframe (DataFrame): The left DataFrame.
|
||||
b_dataframe (DataFrame): The right DataFrame.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing the DataFrame containing the result of division.
|
||||
"""
|
||||
df_out = a_dataframe.div(b_dataframe)
|
||||
return (df_out,)
|
||||
@@ -0,0 +1,43 @@
|
||||
from typing import Any, Dict
|
||||
from io import StringIO
|
||||
import pandas as pd
|
||||
from .utils import jsons_to_series
|
||||
|
||||
class PandasDivSeries:
|
||||
"""
|
||||
PandasDivSeries:
|
||||
A class for dividing a Pandas DataFrame by a Pandas Series.
|
||||
"""
|
||||
|
||||
@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": {
|
||||
"a_dataframe": ("DATAFRAME", {}),
|
||||
"b_series": ("PDSERIES", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def f(self, a_dataframe: pd.DataFrame, b_series: pd.Series) -> tuple:
|
||||
"""
|
||||
Divide a pandas DataFrame by a pandas Series.
|
||||
|
||||
Args:
|
||||
a_dataframe (DataFrame): The numerator DataFrame.
|
||||
b_series (Series): The denominator Series.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing the DataFrame containing the result of division.
|
||||
"""
|
||||
df_out = a_dataframe.div(b_series)
|
||||
return (df_out,)
|
||||
@@ -1,7 +1,5 @@
|
||||
from typing import Any, Dict
|
||||
from io import StringIO
|
||||
import pandas as pd
|
||||
from .utils import index_to_jsons
|
||||
|
||||
class PandasDropNA:
|
||||
"""
|
||||
@@ -19,24 +17,22 @@ class PandasDropNA:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiline": True})
|
||||
"dataframe": ("DATAFRAME", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "dropna"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def dropna(self, dataframe_json: str) -> tuple:
|
||||
def dropna(self, dataframe: pd.DataFrame) -> tuple:
|
||||
"""
|
||||
Returns a DataFrame with missing values removed.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing a JSON string for the DataFrame.
|
||||
tuple: A tuple containing the DataFrame.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
return (df.dropna().to_json(),)
|
||||
return (dataframe.dropna().to_json(),)
|
||||
|
||||
@@ -20,46 +20,43 @@ class PandasGroupBy:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiline": True}),
|
||||
"dataframe": ("DATAFRAME", {}),
|
||||
"column_name": ("STRING", {"default": ""}),
|
||||
"aggragate_function":(("sum", "mean", "count", "std", "min", "max"),)
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "groupby_dataframes"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def groupby_dataframes(self,
|
||||
dataframe_json: str,
|
||||
dataframe: pd.DataFrame,
|
||||
column_name: str,
|
||||
aggragate_function: str) -> tuple:
|
||||
"""
|
||||
Compute aggregate values for groups in a DataFrame
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
column_name (str): The name of the column for use as groups.
|
||||
aggregate_function (str): The type of aggregate function to perform.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing a JSON string of the merged DataFrame.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
|
||||
if aggragate_function == "max":
|
||||
df_out = df.groupby(column_name).max()
|
||||
df_out = dataframe.groupby(column_name).max()
|
||||
elif aggragate_function == "min":
|
||||
df_out = df.groupby(column_name).min()
|
||||
df_out = dataframe.groupby(column_name).min()
|
||||
elif aggragate_function == "std":
|
||||
df_out = df.groupby(column_name).std()
|
||||
df_out = dataframe.groupby(column_name).std()
|
||||
elif aggragate_function == "count":
|
||||
df_out = df.groupby(column_name).count()
|
||||
df_out = dataframe.groupby(column_name).count()
|
||||
elif aggragate_function == "sum":
|
||||
df_out = df.groupby(column_name).sum()
|
||||
df_out = dataframe.groupby(column_name).sum()
|
||||
elif aggragate_function == "mean":
|
||||
df_out = df.groupby(column_name).mean()
|
||||
df_out = dataframe.groupby(column_name).mean()
|
||||
else:
|
||||
raise ValueError("Unsupported aggregate function.")
|
||||
return (df_out.to_json(),)
|
||||
return (df_out,)
|
||||
|
||||
@@ -19,27 +19,25 @@ class PandasHead:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiline": True}),
|
||||
"dataframe": ("DATAFRAME", {}),
|
||||
"rows": ("INT", {"default": 10, "min": 0, "max": 50})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "head"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def head(self, dataframe_json: str, rows: int) -> tuple:
|
||||
def head(self, dataframe: pd.DataFrame, rows: int) -> tuple:
|
||||
"""
|
||||
Returns the first `rows` rows of a pandas DataFrame.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
rows (int): The number of rows to retrieve.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing a JSON string of the resulting DataFrame.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
df2 = df.head(rows)
|
||||
return (df2.to_json(),)
|
||||
df2 = dataframe.head(rows)
|
||||
return (df2,)
|
||||
|
||||
@@ -21,30 +21,28 @@ class PandasIlocRowSeries:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiline": True}),
|
||||
"dataframe": ("DATAFRAME", {}),
|
||||
"row_integer_position": ("INT", {"default": 0, "min": 0, "max": 2**31})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "select_row"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def select_row(self, dataframe_json: str,
|
||||
def select_row(self, dataframe: pd.DataFrame,
|
||||
row_integer_position: int) -> tuple:
|
||||
"""
|
||||
Selects a specific row using a row label (row index) from a pandas DataFrame,
|
||||
and returns the JSON serialized Series object.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
row_integer_position (int): The row integer position.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing the value of the row in string. The string is
|
||||
a JSON string containing the serialized Pandas Series object.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
value = df.iloc[row_integer_position]
|
||||
return (series_to_jsons(value),)
|
||||
value = dataframe.iloc[row_integer_position]
|
||||
return (value,)
|
||||
|
||||
@@ -21,16 +21,16 @@ class PandasIlocRowsDataFrame:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiline": True}),
|
||||
"dataframe": ("DATAFRAME", {}),
|
||||
"row_int_pos_list_json": ("STRING", {"multiline": False})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "select_rows"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def select_rows(self, dataframe_json: str,
|
||||
def select_rows(self, dataframe: pd.DataFrame,
|
||||
row_int_pos_list_json: str) -> tuple:
|
||||
"""
|
||||
Select rows from a pandas DataFrame and returning it as a DataFrame.
|
||||
@@ -38,15 +38,13 @@ class PandasIlocRowsDataFrame:
|
||||
the JSON serialized DataFrame object.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
row_int_pos_list_json (str): A list containing row integer positions.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing the value of the row in string. The string is
|
||||
a JSON string containing the serialized Pandas Series object.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
row_int_pos_list = json.loads(row_int_pos_list_json)
|
||||
df2 = df.iloc[row_int_pos_list]
|
||||
return (df2.to_json(),)
|
||||
df2 = dataframe.iloc[row_int_pos_list]
|
||||
return (df2,)
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
from typing import Any, Dict
|
||||
from io import StringIO
|
||||
import pandas as pd
|
||||
from .utils import index_to_jsons
|
||||
|
||||
class PandasIndex:
|
||||
"""
|
||||
@@ -19,25 +17,23 @@ class PandasIndex:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiline": True})
|
||||
"dataframe": ("DATAFRAME", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("PDINDEX",)
|
||||
FUNCTION: str = "row_index"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def row_index(self, dataframe_json: str) -> tuple:
|
||||
def row_index(self, dataframe: pd.DataFrame) -> tuple:
|
||||
"""
|
||||
Returns the row labels (index) of a pandas DataFrame.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing a JSON string for the serialized pandas.Index containing row labels.
|
||||
tuple: A tuple containing a pandas.Index for row labels.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
row_index = df.index
|
||||
return (index_to_jsons(row_index),)
|
||||
row_index = dataframe.index
|
||||
return (row_index,)
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
from typing import Any, Dict
|
||||
import pandas as pd
|
||||
|
||||
|
||||
class PandasIndexToString:
|
||||
"""
|
||||
PandasIndexToString:
|
||||
A class for converting a pandas Index to a string representation.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls) -> Dict[str, Any]:
|
||||
"""
|
||||
Defines the input types for the `to_string` function.
|
||||
|
||||
Returns:
|
||||
Dict[str, Any]: A dictionary specifying required input types.
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"index": ("PDINDEX", {}),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def f(self, ind: pd.Index) -> tuple:
|
||||
"""
|
||||
Converts a Pandas Index to a string representation.
|
||||
|
||||
Args:
|
||||
ind (pd.Index): The index.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing the string representation of the Index.
|
||||
"""
|
||||
return (str(ind),)
|
||||
@@ -1,7 +1,6 @@
|
||||
from typing import Any, Dict
|
||||
from io import StringIO
|
||||
import pandas as pd
|
||||
from .utils import index_to_jsons
|
||||
|
||||
|
||||
class PandasIsNA:
|
||||
"""
|
||||
@@ -19,24 +18,22 @@ class PandasIsNA:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiline": True})
|
||||
"dataframe": ("DATAFRAME", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "isna"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def isna(self, dataframe_json: str) -> tuple:
|
||||
def isna(self, dataframe: pd.DataFrame) -> tuple:
|
||||
"""
|
||||
Returns a DataFrame with boolean values with True indicating a missing value.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing a JSON string for the DataFrame.
|
||||
tuple: A tuple containing the DataFrame.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
return (df.isna().to_json(),)
|
||||
return (dataframe.isna(),)
|
||||
|
||||
@@ -19,33 +19,29 @@ class PandasJoin:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"left_dataframe_json": ("STRING", {"multiline": True}),
|
||||
"right_dataframe_json": ("STRING", {"multiline": True}),
|
||||
"left_dataframe": ("DATAFRAME", {}),
|
||||
"right_dataframe": ("DATAFRAME", {}),
|
||||
"on_column_name": ("STRING", {"default": ""}),
|
||||
"join_method":(("inner", "left", "right", "outer"),)
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "join_dataframes"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def join_dataframes(self, left_dataframe_json: str, right_dataframe_json: str, on_column_name: str, join_method: str) -> tuple:
|
||||
def join_dataframes(self, left_dataframe: pd.DataFrame, right_dataframe: pd.DataFrame, on_column_name: str, join_method: str) -> tuple:
|
||||
"""
|
||||
Merges two pandas DataFrames based on a common column using the specified join method.
|
||||
|
||||
Args:
|
||||
left_dataframe_json (str): A JSON string representation of the left DataFrame.
|
||||
right_dataframe_json (str): A JSON string representation of the right DataFrame.
|
||||
left_dataframe (DataFrame): The left DataFrame.
|
||||
right_dataframe (DataFrame): The right DataFrame.
|
||||
on_column_name (str): The name of the column to join on.
|
||||
join_method (str): The type of join to perform ("inner", "left", "right", "outer").
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing a JSON string of the merged DataFrame.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df_left = pd.read_json(StringIO(left_dataframe_json))
|
||||
df_right = pd.read_json(StringIO(right_dataframe_json))
|
||||
|
||||
df_out = pd.merge(df_left, df_right, on=on_column_name, how=join_method)
|
||||
return (df_out.to_json(),)
|
||||
df_out = pd.merge(left_dataframe, right_dataframe, on=on_column_name, how=join_method)
|
||||
return (df_out,)
|
||||
|
||||
@@ -23,7 +23,7 @@ class PandasLoadCSV:
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "load_csv"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
@@ -39,8 +39,4 @@ class PandasLoadCSV:
|
||||
"""
|
||||
# Read CSV file into DataFrame
|
||||
df = pd.read_csv(file_path)
|
||||
|
||||
# Convert DataFrame to JSON
|
||||
result_json = df.to_json()
|
||||
|
||||
return (result_json,)
|
||||
return (df,)
|
||||
|
||||
@@ -24,7 +24,7 @@ class PandasLoadCSVWithEncoding:
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "load_csv"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
@@ -44,8 +44,4 @@ class PandasLoadCSVWithEncoding:
|
||||
"""
|
||||
# Read CSV file into DataFrame
|
||||
df = pd.read_csv(file_path, encoding=encoding)
|
||||
|
||||
# Convert DataFrame to JSON
|
||||
result_json = df.to_json()
|
||||
|
||||
return (result_json,)
|
||||
return (df,)
|
||||
|
||||
@@ -25,7 +25,7 @@ class PandasLoadCSVWithIndex:
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "load_csv"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
@@ -42,8 +42,4 @@ class PandasLoadCSVWithIndex:
|
||||
"""
|
||||
# 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,)
|
||||
return (df,)
|
||||
|
||||
@@ -23,7 +23,7 @@ class PandasLoadJSON:
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "load_json"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
@@ -39,8 +39,4 @@ class PandasLoadJSON:
|
||||
"""
|
||||
# Read JSON file into DataFrame
|
||||
df = pd.read_json(file_path)
|
||||
|
||||
# Convert DataFrame to JSON
|
||||
result_json = df.to_json()
|
||||
|
||||
return (result_json,)
|
||||
return (df,)
|
||||
|
||||
@@ -18,7 +18,7 @@ class PandasLocCellStr:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiline": True}),
|
||||
"dataframe": ("DATAFRAME", {}),
|
||||
"row_index": ("STRING", {"default": ""}),
|
||||
"row_index_type":(("string", "int"),),
|
||||
"column_label": ("STRING", {"default": ""}),
|
||||
@@ -30,7 +30,7 @@ class PandasLocCellStr:
|
||||
FUNCTION: str = "cell"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def cell(self, dataframe_json: str,
|
||||
def cell(self, dataframe: pd.DataFrame,
|
||||
row_index: str,
|
||||
row_index_type: str,
|
||||
column_label: str,
|
||||
@@ -39,7 +39,7 @@ class PandasLocCellStr:
|
||||
Selects specific cell from a pandas DataFrame.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
row_index (str): The row index (row label) for the cell.
|
||||
row_index_type (str): The data type of the row index.
|
||||
column_label (str): The column label for the cell.
|
||||
@@ -48,10 +48,8 @@ class PandasLocCellStr:
|
||||
Returns:
|
||||
tuple: A tuple containing the value of the cell in string.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
row_index = int(row_index) if row_index_type == "int" else row_index
|
||||
column_label = int(column_label) if column_label_type == "int" else column_label
|
||||
|
||||
value = df.loc[row_index, column_label]
|
||||
value = dataframe.loc[row_index, column_label]
|
||||
return (str(value),)
|
||||
|
||||
@@ -19,35 +19,31 @@ class PandasLocRowSeries:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiline": True}),
|
||||
"dataframe": ("DATAFRAME", {}),
|
||||
"row_index": ("STRING", {"default": ""}),
|
||||
"row_index_type":(("string", "int"),)
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("PDSERIES",)
|
||||
FUNCTION: str = "select_row"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def select_row(self, dataframe_json: str,
|
||||
def select_row(self, dataframe: pd.DataFrame,
|
||||
row_index: str,
|
||||
row_index_type: str) -> tuple:
|
||||
"""
|
||||
Selects a specific row using a row label (row index) from a pandas DataFrame,
|
||||
and returns the JSON serialized Series object.
|
||||
and returns the Series object.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
row_index (str): The row index (row label) for the row.
|
||||
row_index_type (str): The data type of the row index.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing the value of the row in string. The string is
|
||||
a JSON string containing the serialized Pandas Series object.
|
||||
tuple: A tuple containing the value of the row in the serialized Pandas Series object.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
row_index = int(row_index) if row_index_type == "int" else row_index
|
||||
|
||||
value = df.loc[row_index]
|
||||
return (series_to_jsons(value),)
|
||||
value = dataframe.loc[row_index]
|
||||
return (value,)
|
||||
|
||||
@@ -19,24 +19,22 @@ class PandasMax:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiline": True})
|
||||
"dataframe": ("DATAFRAME", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("PDSERIES",)
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def f(self, dataframe_json: str) -> tuple:
|
||||
def f(self, dataframe: pd.DataFrame) -> tuple:
|
||||
"""
|
||||
Returns a Series with max for each column.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing a JSON string for the Series.
|
||||
tuple: A tuple containing the Series.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
return (series_to_jsons(df.max()),)
|
||||
return (dataframe.max(),)
|
||||
|
||||
@@ -19,24 +19,22 @@ class PandasMean:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiline": True})
|
||||
"dataframe": ("DATAFRAME", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("PDSERIES",)
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def f(self, dataframe_json: str) -> tuple:
|
||||
def f(self, dataframe: pd.DataFrame) -> tuple:
|
||||
"""
|
||||
Returns a Series with mean for each column.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing a JSON string for the Series.
|
||||
tuple: A tuple containing the Series.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
return (series_to_jsons(df.mean()),)
|
||||
return (dataframe.mean(),)
|
||||
@@ -19,24 +19,22 @@ class PandasMedian:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiline": True})
|
||||
"dataframe": ("DATAFRAME", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("PDSERIES",)
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def f(self, dataframe_json: str) -> tuple:
|
||||
def f(self, dataframe: pd.DataFrame) -> tuple:
|
||||
"""
|
||||
Returns a Series with median for each column.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing a JSON string for the Series.
|
||||
tuple: A tuple containing the Series.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
return (series_to_jsons(df.median()),)
|
||||
return (dataframe.median(),)
|
||||
|
||||
@@ -19,24 +19,22 @@ class PandasMin:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiline": True})
|
||||
"dataframe": ("DATAFRAME", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("PDSERIES",)
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def f(self, dataframe_json: str) -> tuple:
|
||||
def f(self, dataframe: pd.DataFrame) -> tuple:
|
||||
"""
|
||||
Returns a Series with min for each column.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing a JSON string for the Series.
|
||||
tuple: A tuple containing the Series.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
return (series_to_jsons(df.min()),)
|
||||
return (dataframe.min(),)
|
||||
|
||||
@@ -18,24 +18,22 @@ class PandasMode:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiline": True})
|
||||
"dataframe": ("DATAFRAME", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def f(self, dataframe_json: str) -> tuple:
|
||||
def f(self, dataframe: pd.DataFrame) -> tuple:
|
||||
"""
|
||||
Returns a DataFrame with mode for each column.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing a JSON string for the DataFrame.
|
||||
tuple: A tuple containing the DataFrame.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
return (df.mode().to_json(),)
|
||||
return (dataframe.mode(),)
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
from typing import Any, Dict
|
||||
from io import StringIO
|
||||
import pandas as pd
|
||||
|
||||
|
||||
class PandasMul:
|
||||
"""
|
||||
PandasMul:
|
||||
A class for multiplying two pandas DataFrames.
|
||||
"""
|
||||
|
||||
@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": {
|
||||
"a_dataframe": ("DATAFRAME", {}),
|
||||
"b_dataframe": ("DATAFRAME", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def f(self, a_dataframe: pd.DataFrame, b_dataframe: pd.DataFrame) -> tuple:
|
||||
"""
|
||||
Multiply two pandas DataFrames.
|
||||
|
||||
Args:
|
||||
a_dataframe (DataFrame): The left DataFrame.
|
||||
b_dataframe (DataFrame): The right DataFrame.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing the DataFrame containing the result of multiplication.
|
||||
"""
|
||||
df_out = a_dataframe.mul(b_dataframe)
|
||||
return (df_out,)
|
||||
@@ -0,0 +1,43 @@
|
||||
from typing import Any, Dict
|
||||
from io import StringIO
|
||||
import pandas as pd
|
||||
from .utils import jsons_to_series
|
||||
|
||||
class PandasMulSeries:
|
||||
"""
|
||||
PandasMulSeries:
|
||||
A class for multiplying a Pandas DataFrame by a Pandas Series.
|
||||
"""
|
||||
|
||||
@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": {
|
||||
"a_dataframe": ("DATAFRAME", {}),
|
||||
"b_series": ("PDSERIES", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def f(self, a_dataframe: pd.DataFrame, b_series: pd.Series) -> tuple:
|
||||
"""
|
||||
Multiply a pandas DataFrame by a pandas Series.
|
||||
|
||||
Args:
|
||||
a_dataframe (DataFrame): The DataFrame.
|
||||
b_series (Series): The Series.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing the DataFrame containing the result of multiplication.
|
||||
"""
|
||||
df_out = a_dataframe.mul(b_series)
|
||||
return (df_out,)
|
||||
@@ -0,0 +1,46 @@
|
||||
from typing import Any, Dict
|
||||
from io import StringIO
|
||||
import pandas as pd
|
||||
|
||||
|
||||
class PandasPow:
|
||||
"""
|
||||
PandasPow:
|
||||
A class for exponentiating two pandas DataFrames.
|
||||
"""
|
||||
|
||||
@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": {
|
||||
# "a_dataframe": ("DATAFRAME", {}),
|
||||
# "b_dataframe": ("DATAFRAME", {})
|
||||
"a_dataframe": ("DATAFRAME", {}),
|
||||
"b_dataframe": ("DATAFRAME", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
# def f(self, a_dataframe: pd.DataFrame, b_dataframe: pd.DataFrame) -> tuple:
|
||||
def f(self, a_dataframe: pd.DataFrame, b_dataframe: pd.DataFrame) -> tuple:
|
||||
"""
|
||||
Raise one pandas DataFrame to the power of another.
|
||||
|
||||
Args:
|
||||
a_dataframe (DataFrame): The base DataFrame.
|
||||
b_dataframe (DataFrame): The exponent DataFrame.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing the DataFrame containing the result of exponentiation.
|
||||
"""
|
||||
df_out = a_dataframe.pow(b_dataframe)
|
||||
return (df_out,)
|
||||
@@ -0,0 +1,43 @@
|
||||
from typing import Any, Dict
|
||||
from io import StringIO
|
||||
import pandas as pd
|
||||
from .utils import jsons_to_series
|
||||
|
||||
class PandasPowSeries:
|
||||
"""
|
||||
PandasPowSeries:
|
||||
A class for raising a Pandas DataFrame to the power of a Pandas Series.
|
||||
"""
|
||||
|
||||
@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": {
|
||||
"a_dataframe": ("DATAFRAME", {}),
|
||||
"b_series": ("PDSERIES", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def f(self, a_dataframe: pd.DataFrame, b_series: pd.Series) -> tuple:
|
||||
"""
|
||||
Raise a pandas DataFrame to the power of a pandas Series.
|
||||
|
||||
Args:
|
||||
a_dataframe (DataFrame): The base DataFrame.
|
||||
b_series (Series): The exponent Series.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing the DataFrame containing the result of exponentiation.
|
||||
"""
|
||||
df_out = a_dataframe.pow(b_series)
|
||||
return (df_out,)
|
||||
@@ -17,7 +17,7 @@ class PandasSaveCSV:
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"forceInput": True}),
|
||||
"dataframe": ("DATAFRAME", {}),
|
||||
"file_path": ("STRING", {"multiline": False})
|
||||
},
|
||||
"hidden": {
|
||||
@@ -34,7 +34,7 @@ class PandasSaveCSV:
|
||||
|
||||
CATEGORY = "Data Analysis"
|
||||
|
||||
def save_csv(self, dataframe_json,file_path=None, unique_id=None, extra_pnginfo=None):
|
||||
def save_csv(self, dataframe, file_path=None, unique_id=None, extra_pnginfo=None):
|
||||
text = None
|
||||
if unique_id is not None and extra_pnginfo is not None:
|
||||
if not isinstance(extra_pnginfo, list):
|
||||
@@ -47,8 +47,7 @@ class PandasSaveCSV:
|
||||
elif file_path is None or len(file_path) == 0:
|
||||
print("Error: file path is not specified")
|
||||
else:
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json[0]))
|
||||
df = dataframe[0]
|
||||
df.to_csv(path_or_buf=file_path[0]) # Save as CSV
|
||||
text = [str(df)] # wrap in list
|
||||
workflow = extra_pnginfo[0]["workflow"]
|
||||
|
||||
@@ -17,7 +17,7 @@ class PandasSaveJSON:
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"forceInput": True}),
|
||||
"dataframe": ("DATAFRAME", {}),
|
||||
"file_path": ("STRING", {"multiline": False})
|
||||
},
|
||||
"hidden": {
|
||||
@@ -34,7 +34,7 @@ class PandasSaveJSON:
|
||||
|
||||
CATEGORY = "Data Analysis"
|
||||
|
||||
def save_json(self, dataframe_json,file_path=None, unique_id=None, extra_pnginfo=None):
|
||||
def save_json(self, dataframe, file_path=None, unique_id=None, extra_pnginfo=None):
|
||||
text = None
|
||||
if unique_id is not None and extra_pnginfo is not None:
|
||||
if not isinstance(extra_pnginfo, list):
|
||||
@@ -47,8 +47,7 @@ class PandasSaveJSON:
|
||||
elif file_path is None or len(file_path) == 0:
|
||||
print("Error: file path is not specified")
|
||||
else:
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json[0]))
|
||||
df = dataframe[0]
|
||||
df.to_json(path_or_buf=file_path[0]) # Save as JSON
|
||||
text = [str(df)] # wrap in list
|
||||
workflow = extra_pnginfo[0]["workflow"]
|
||||
|
||||
@@ -18,31 +18,26 @@ class PandasSelectColumns:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiline": True}),
|
||||
"dataframe": ("DATAFRAME", {}),
|
||||
"column_names": ("STRING", {"default": ""})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "select_columns"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def select_columns(self, dataframe_json: str, column_names: str) -> tuple:
|
||||
def select_columns(self, dataframe: pd.DataFrame, column_names: str) -> tuple:
|
||||
"""
|
||||
Selects specific columns from a pandas DataFrame.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
column_names (str): A comma-separated string of column names to select.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing a JSON string of the DataFrame with selected columns.
|
||||
tuple: A tuple containing the DataFrame with selected columns.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
|
||||
# Process column names
|
||||
selected_columns = [col.strip() for col in column_names.split(",")]
|
||||
df2 = df[selected_columns]
|
||||
|
||||
return (df2.to_json(),)
|
||||
df2 = dataframe[selected_columns]
|
||||
return (df2,)
|
||||
|
||||
@@ -18,30 +18,26 @@ class PandasSelectRows:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiline": True}),
|
||||
"dataframe": ("DATAFRAME", {}),
|
||||
"condition": ("STRING", {"default": ""})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "select_rows"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def select_rows(self, dataframe_json: str, condition: str) -> tuple:
|
||||
def select_rows(self, dataframe: pd.DataFrame, condition: str) -> tuple:
|
||||
"""
|
||||
Selects specific rows from a pandas DataFrame based on a given condition.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
condition (str): A string representing the condition to filter rows.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing a JSON string of the filtered DataFrame.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
|
||||
# Apply condition
|
||||
df2 = df.query(condition)
|
||||
|
||||
return (df2.to_json(),)
|
||||
df2 = dataframe.query(condition)
|
||||
return (df2,)
|
||||
|
||||
@@ -19,7 +19,7 @@ class PandasSeriesToString:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"series_json": ("STRING", {"multiline": True}),
|
||||
"series": ("PDSERIES", {}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,16 +27,14 @@ class PandasSeriesToString:
|
||||
FUNCTION: str = "series_to_string"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def series_to_string(self, series_json: str) -> tuple:
|
||||
def series_to_string(self, series: pd.Series) -> tuple:
|
||||
"""
|
||||
Converts a Pandas Series to a string representation.
|
||||
|
||||
Args:
|
||||
series_json (str): A JSON string representation of the Series.
|
||||
series (Series): The Series.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing the string representation of the Series.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
series = jsons_to_series(series_json)
|
||||
return (str(series),)
|
||||
|
||||
@@ -12,7 +12,7 @@ class PandasShowDataFrame:
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"forceInput": True}),
|
||||
"dataframe": ("DATAFRAME", {})
|
||||
},
|
||||
"hidden": {
|
||||
"unique_id": "UNIQUE_ID",
|
||||
@@ -28,7 +28,7 @@ class PandasShowDataFrame:
|
||||
|
||||
CATEGORY = "Data Analysis"
|
||||
|
||||
def notify(self, dataframe_json, unique_id=None, extra_pnginfo=None):
|
||||
def notify(self, dataframe, unique_id=None, extra_pnginfo=None):
|
||||
text = None
|
||||
if unique_id is not None and extra_pnginfo is not None:
|
||||
if not isinstance(extra_pnginfo, list):
|
||||
@@ -39,8 +39,7 @@ class PandasShowDataFrame:
|
||||
):
|
||||
print("Error: extra_pnginfo[0] is not a dict or missing 'workflow' key")
|
||||
else:
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json[0]))
|
||||
df = dataframe[0]
|
||||
text = [str(df)] # wrap in list
|
||||
workflow = extra_pnginfo[0]["workflow"]
|
||||
node = next(
|
||||
@@ -48,7 +47,11 @@ class PandasShowDataFrame:
|
||||
None,
|
||||
)
|
||||
if node:
|
||||
node["widgets_values"] = [text]
|
||||
node["widgets_values"] = text # [text]
|
||||
else:
|
||||
print("unique_id or extra_pnginfo is None.")
|
||||
return {"ui": {"text": text}, "result": (text,)}
|
||||
|
||||
# "ui" value is the one that is shown on the node UI.
|
||||
# Note that "ui" return value needs to a list of strings.
|
||||
return {"ui": {"text": text},
|
||||
"result": (text,)}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
"""
|
||||
This code is based on
|
||||
https://github.com/pythongosssss/ComfyUI-Custom-Scripts/blob/main/py/show_text.py
|
||||
|
||||
See credit/credit.md for the full license.
|
||||
"""
|
||||
import pandas as pd
|
||||
|
||||
class PandasShowIndex:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"index_list": ("PDINDEX", {}),
|
||||
},
|
||||
"hidden": {
|
||||
"unique_id": "UNIQUE_ID",
|
||||
"extra_pnginfo": "EXTRA_PNGINFO",
|
||||
},
|
||||
}
|
||||
|
||||
INPUT_IS_LIST = True
|
||||
RETURN_TYPES = ("STRING",)
|
||||
FUNCTION = "notify"
|
||||
OUTPUT_NODE = True
|
||||
OUTPUT_IS_LIST = (True,)
|
||||
|
||||
CATEGORY = "Data Analysis"
|
||||
|
||||
def notify(self, index_list, unique_id=None, extra_pnginfo=None):
|
||||
text = None
|
||||
if unique_id is not None and extra_pnginfo is not None:
|
||||
if not isinstance(extra_pnginfo, list):
|
||||
print("Error: extra_pnginfo is not a list")
|
||||
elif (
|
||||
not isinstance(extra_pnginfo[0], dict)
|
||||
or "workflow" not in extra_pnginfo[0]
|
||||
):
|
||||
print("Error: extra_pnginfo[0] is not a dict or missing 'workflow' key")
|
||||
else:
|
||||
ind = index_list[0]
|
||||
text = [str(ind)] # wrap in list
|
||||
workflow = extra_pnginfo[0]["workflow"]
|
||||
node = next(
|
||||
(x for x in workflow["nodes"] if str(x["id"]) == str(unique_id[0])),
|
||||
None,
|
||||
)
|
||||
if node:
|
||||
node["widgets_values"] = [text]
|
||||
else:
|
||||
print("unique_id or extra_pnginfo is None.")
|
||||
return {"ui": {"text": text}, "result": (text,)}
|
||||
@@ -14,7 +14,7 @@ class PandasShowSeries:
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"series_json": ("STRING", {"forceInput": True}),
|
||||
"series_list": ("PDSERIES", {}),
|
||||
},
|
||||
"hidden": {
|
||||
"unique_id": "UNIQUE_ID",
|
||||
@@ -30,7 +30,7 @@ class PandasShowSeries:
|
||||
|
||||
CATEGORY = "Data Analysis"
|
||||
|
||||
def notify(self, series_json, unique_id=None, extra_pnginfo=None):
|
||||
def notify(self, series_list, unique_id=None, extra_pnginfo=None):
|
||||
text = None
|
||||
if unique_id is not None and extra_pnginfo is not None:
|
||||
if not isinstance(extra_pnginfo, list):
|
||||
@@ -41,8 +41,7 @@ class PandasShowSeries:
|
||||
):
|
||||
print("Error: extra_pnginfo[0] is not a dict or missing 'workflow' key")
|
||||
else:
|
||||
# Deserialize JSON string to DataFrame
|
||||
series = jsons_to_series(series_json[0])
|
||||
series = series_list[0]
|
||||
text = [series_to_jsons(series)] # wrap in list
|
||||
workflow = extra_pnginfo[0]["workflow"]
|
||||
node = next(
|
||||
|
||||
@@ -18,32 +18,27 @@ class PandasSort:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiline": True}),
|
||||
"dataframe": ("DATAFRAME", {}),
|
||||
"column_name": ("STRING", {"default": ""}),
|
||||
"ascending": ("BOOLEAN", {"default": True})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "sort_rows"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def sort_rows(self, dataframe_json: str, column_name: str, ascending: bool) -> tuple:
|
||||
def sort_rows(self, dataframe: pd.DataFrame, column_name: str, ascending: bool) -> tuple:
|
||||
"""
|
||||
Sorts a pandas DataFrame by the specified column.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
column_name (str): The name of the column to sort by.
|
||||
ascending (bool): Whether to sort in ascending order.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing a JSON string of the sorted DataFrame.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
|
||||
# Sort DataFrame
|
||||
df2 = df.sort_values(by=column_name, ascending=ascending)
|
||||
|
||||
return (df2.to_json(),)
|
||||
df2 = dataframe.sort_values(by=column_name, ascending=ascending)
|
||||
return (df2,)
|
||||
|
||||
@@ -19,24 +19,22 @@ class PandasStd:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiline": True})
|
||||
"dataframe": ("DATAFRAME", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("PDSERIES",)
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def f(self, dataframe_json: str) -> tuple:
|
||||
def f(self, dataframe: pd.DataFrame) -> tuple:
|
||||
"""
|
||||
Returns a Series with standard deviation for each column.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing a JSON string for the Series.
|
||||
tuple: A tuple containing the Series.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
return (series_to_jsons(df.std()),)
|
||||
return (dataframe.std(),)
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
from typing import Any, Dict
|
||||
from io import StringIO
|
||||
import pandas as pd
|
||||
|
||||
|
||||
class PandasSub:
|
||||
"""
|
||||
PandasSub:
|
||||
A class for subtracting two pandas DataFrames.
|
||||
"""
|
||||
|
||||
@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": {
|
||||
"a_dataframe": ("DATAFRAME", {}),
|
||||
"b_dataframe": ("DATAFRAME", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def f(self, a_dataframe: pd.DataFrame, b_dataframe: pd.DataFrame) -> tuple:
|
||||
"""
|
||||
Subtract two pandas DataFrames.
|
||||
|
||||
Args:
|
||||
a_dataframe (DataFrame): The left DataFrame.
|
||||
b_dataframe (DataFrame): The right DataFrame.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing the DataFrame containing the result of subtraction.
|
||||
"""
|
||||
df_out = a_dataframe.sub(b_dataframe)
|
||||
return (df_out,)
|
||||
@@ -0,0 +1,43 @@
|
||||
from typing import Any, Dict
|
||||
from io import StringIO
|
||||
import pandas as pd
|
||||
from .utils import jsons_to_series
|
||||
|
||||
class PandasSubSeries:
|
||||
"""
|
||||
PandasSubSeries:
|
||||
A class for subtracting a Pandas Series 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": {
|
||||
"a_dataframe": ("DATAFRAME", {}),
|
||||
"b_series": ("PDSERIES", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def f(self, a_dataframe: pd.DataFrame, b_series: pd.Series) -> tuple:
|
||||
"""
|
||||
Subtract a pandas Series from a pandas DataFrame.
|
||||
|
||||
Args:
|
||||
a_dataframe (DataFrame): The DataFrame.
|
||||
b_series (Series): The Series.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing the DataFrame containing the result of subtraction.
|
||||
"""
|
||||
df_out = a_dataframe.sub(b_series)
|
||||
return (df_out,)
|
||||
@@ -19,24 +19,22 @@ class PandasSum:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiline": True})
|
||||
"dataframe": ("DATAFRAME", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("PDSERIES",)
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def f(self, dataframe_json: str) -> tuple:
|
||||
def f(self, dataframe: pd.DataFrame) -> tuple:
|
||||
"""
|
||||
Returns a Series with sum for each column.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing a JSON string for the Series.
|
||||
tuple: A tuple containing the Series.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
return (series_to_jsons(df.sum()),)
|
||||
return (dataframe.sum(),)
|
||||
|
||||
@@ -18,28 +18,23 @@ class PandasSummary:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiline": True}),
|
||||
"dataframe": ("DATAFRAME", {}),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("DATAFRAME",)
|
||||
FUNCTION: str = "analyze_dataframe"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def analyze_dataframe(self, dataframe_json: str) -> tuple:
|
||||
def analyze_dataframe(self, dataframe: pd.DataFrame) -> tuple:
|
||||
"""
|
||||
Analyzes a pandas DataFrame and returns a summary.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing a string representation of the DataFrame summary.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
|
||||
# Perform summary operation
|
||||
summary = df.describe()
|
||||
|
||||
summary = dataframe.describe()
|
||||
return (str(summary),)
|
||||
|
||||
@@ -18,7 +18,7 @@ class PandasToString:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiline": True}),
|
||||
"dataframe": ("DATAFRAME", {}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,16 +26,14 @@ class PandasToString:
|
||||
FUNCTION: str = "to_string"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def to_string(self, dataframe_json: str) -> tuple:
|
||||
def to_string(self, dataframe: pd.DataFrame) -> tuple:
|
||||
"""
|
||||
Converts a pandas DataFrame to a string representation.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing the string representation of the DataFrame.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
return (str(df),)
|
||||
return (str(dataframe),)
|
||||
|
||||
@@ -19,24 +19,22 @@ class PandasVar:
|
||||
"""
|
||||
return {
|
||||
"required": {
|
||||
"dataframe_json": ("STRING", {"multiline": True})
|
||||
"dataframe": ("DATAFRAME", {})
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES: tuple = ("STRING",)
|
||||
RETURN_TYPES: tuple = ("PDSERIES",)
|
||||
FUNCTION: str = "f"
|
||||
CATEGORY: str = "Data Analysis"
|
||||
|
||||
def f(self, dataframe_json: str) -> tuple:
|
||||
def f(self, dataframe: pd.DataFrame) -> tuple:
|
||||
"""
|
||||
Returns a Series with variance for each column.
|
||||
|
||||
Args:
|
||||
dataframe_json (str): A JSON string representation of the DataFrame.
|
||||
dataframe (DataFrame): The DataFrame.
|
||||
|
||||
Returns:
|
||||
tuple: A tuple containing a JSON string for the Series.
|
||||
tuple: A tuple containing the Series.
|
||||
"""
|
||||
# Deserialize JSON string to DataFrame
|
||||
df = pd.read_json(StringIO(dataframe_json))
|
||||
return (series_to_jsons(df.var()),)
|
||||
return (dataframe.var(),)
|
||||
|
||||
Reference in New Issue
Block a user