Pandas

The PandasTools toolkit enables an Agent to perform data manipulation tasks using the Pandas library.

PandasTools enable an Agent to perform data manipulation tasks using the Pandas library.

1from kern.agent import Agent
2from kern.tools.pandas import PandasTools
3
4# Create an agent with PandasTools
5agent = Agent(tools=[PandasTools()])
6
7# Example: Create a dataframe with sample data and get the first 5 rows
8agent.print_response("""
9Please perform these tasks:
101. Create a pandas dataframe named 'sales_data' using DataFrame() with this sample data:
11 {'date': ['2023-01-01', '2023-01-02', '2023-01-03', '2023-01-04', '2023-01-05'],
12 'product': ['Widget A', 'Widget B', 'Widget A', 'Widget C', 'Widget B'],
13 'quantity': [10, 15, 8, 12, 20],
14 'price': [9.99, 15.99, 9.99, 12.99, 15.99]}
152. Show me the first 5 rows of the sales_data dataframe
16""")

Toolkit Params

ParameterTypeDefaultDescription
enable_create_pandas_dataframeboolTrueEnables functionality to create pandas DataFrames.
enable_run_dataframe_operationboolTrueEnables functionality to run DataFrame operations.
allboolFalseEnables all functionality when set to True.

Toolkit Functions

FunctionDescription
create_pandas_dataframeCreates a Pandas DataFrame named dataframe_name by using the specified function create_using_function with parameters function_parameters. Parameters include 'dataframe_name' for the name of the DataFrame, 'create_using_function' for the function to create it (e.g., 'read_csv'), and 'function_parameters' for the arguments required by the function. Returns the name of the created DataFrame if successful, otherwise returns an error message.
run_dataframe_operationRuns a specified operation operation on a DataFrame dataframe_name with the parameters operation_parameters. Parameters include 'dataframe_name' for the DataFrame to operate on, 'operation' for the operation to perform (e.g., 'head', 'tail'), and 'operation_parameters' for the arguments required by the operation. Returns the result of the operation if successful, otherwise returns an error message.

Developer Resources