| 195 | |
| 196 | |
| 197 | def read_data_file(file_path: Path, max_rows: int = 10) -> str: |
| 198 | |
| 199 | try: |
| 200 | if file_path.suffix.lower() == '.csv': |
| 201 | df = pd.read_csv(file_path) |
| 202 | elif file_path.suffix.lower() == '.xlsx': |
| 203 | df = pd.read_excel(file_path) |
| 204 | else: |
| 205 | return f"Unsupported file format: {file_path.suffix}" |
| 206 | |
| 207 | info = f"Dataset: {file_path.name}\n" |
| 208 | info += f"Shape: {df.shape}\n" |
| 209 | info += f"Columns: {list(df.columns)}\n\n" |
| 210 | |
| 211 | info += "Data types:\n" |
| 212 | for col, dtype in df.dtypes.items(): |
| 213 | info += f" {col}: {dtype}\n" |
| 214 | info += "\n" |
| 215 | |
| 216 | info += f"First {min(max_rows, len(df))} rows:\n" |
| 217 | info += df.head(max_rows).to_string(index=False) |
| 218 | |
| 219 | return info |
| 220 | |
| 221 | except Exception as e: |
| 222 | return f"Error reading {file_path.name}: {str(e)}" |
| 223 | |
| 224 | |
| 225 | def create_user_prompt(category: str, data_info: Dict[str, str]) -> str: |