2023-03-18 12:26:19 +00:00
|
|
|
import pandas as pd
|
2023-03-20 08:27:20 +00:00
|
|
|
|
2023-03-23 07:33:45 +00:00
|
|
|
from core.prompts.file import DATAFRAME_PROMPT
|
2023-03-18 12:26:19 +00:00
|
|
|
|
2023-03-23 07:33:45 +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 = (
|
2023-04-07 02:11:24 +00:00
|
|
|
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)
|