Upload pandas_dataframe_tool.py
Browse files- pandas_dataframe_tool.py +13 -0
pandas_dataframe_tool.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import Tool
|
| 2 |
+
import pandas as pd
|
| 3 |
+
|
| 4 |
+
class PandasDataFrameTool(Tool):
|
| 5 |
+
name = "pandas_dataframe_tool"
|
| 6 |
+
description = "This tool counts the number of rows in a Pandas DataFrame."
|
| 7 |
+
|
| 8 |
+
inputs = ["dataframe"]
|
| 9 |
+
outputs = ["text"]
|
| 10 |
+
|
| 11 |
+
def __call__(self, dataframe: pd.DataFrame):
|
| 12 |
+
num_rows = len(dataframe)
|
| 13 |
+
return f"The DataFrame has {num_rows} rows."
|