EVAL/core/handlers/dataframe.py

22 lines
596 B
Python
Raw Normal View History

2023-03-18 12:26:19 +00:00
import pandas as pd
2023-03-20 08:27:20 +00:00
from core.prompts.file import DATAFRAME_PROMPT
2023-03-18 12:26:19 +00:00
from .base import BaseHandler
2023-03-18 12:26:19 +00:00
class CsvToDataframe(BaseHandler):
def handle(self, filename: str):
df = pd.read_csv(filename)
2023-03-20 08:27:20 +00:00
description = (
f"Dataframe with {len(df)} rows and {len(df.columns)} columns. "
2023-03-20 08:27:20 +00:00
"Columns are: "
f"{', '.join(df.columns)}"
)
print(
f"\nProcessed CsvToDataframe, Input CSV: {filename}, Output Description: {description}"
)
2023-03-18 12:26:19 +00:00
return DATAFRAME_PROMPT.format(filename=filename, description=description)