Data analysis code generation
/generateGenerate the data analysis code in the language `$1` for the analysis type `$2` using the code-generating subagent.
--- allowed-tools: Task, Read, Write, Bash, Grep, Glob argument-hint: [language] [analysis_type] description: Generate analysis code in specified language and analysis type --- # Code Generation Command Generate data analysis code in $1 language for $2 analysis type using the code-generator subagent. ## Context - Programming language: $1 (python, r, sql, javascript) - Analysis type: $2 (data-cleaning, statistical, visualization, machine-learning, custom) - Current working directory: !pwd - Output directory: ./generated_code/ - Available libraries and frameworks based on language ## Your Task Use the code-generator subagent to create high-quality, production-ready analysis code: ### 1. Requirements Analysis - Understand the specific analysis requirements - Identify appropriate libraries and frameworks - Consider data types and volumes - Plan for scalability and performance ### 2. Code Architecture - Design modular, reusable code structure - Implement proper error handling - Include comprehensive documentation - Add unit tests where appropriate ### 3. Implementation - Write clean, efficient, and maintainable code - Include proper data validation - Implement best practices for the language - Add logging and debugging capabilities ### 4. Documentation - Create comprehensive code documentation - Include usage examples and tutorials - Provide troubleshooting guidance - Document dependencies and requirements ## Language Support ### Python - Libraries: pandas, numpy, matplotlib, seaborn, scikit-learn, plotly - Use Cases: Data cleaning, statistical analysis, machine learning, visualization - Output: Jupyter notebooks, Python scripts, modules ### R - Libraries: tidyverse, ggplot2, dplyr, caret, shiny - Use Cases: Statistical analysis, data visualization, bioinformatics - Output: R scripts, R Markdown documents, Shiny apps ### SQL - Dialects: PostgreSQL, MySQL, SQLite, BigQuery, Redshift - Use Cases: Data extraction, aggregation, reporting, ETL - Output: SQL queries, stored procedures, views ### JavaScript - Libraries: D3.js, Plotly.js, Chart.js, TensorFlow.js - Use Cases: Web visualizations, interactive dashboards, client-side ML - Output: HTML/JS files, Node.js scripts, web applications ## Analysis Types ### Data Cleaning - Missing value handling - Outlier detection and treatment - Data type conversion - Normalization and standardization - Feature engineering ### Statistical Analysis - Descriptive statistics - Hypothesis testing - Correlation and regression - Time series analysis - ANOVA and t-tests ### Visualization - Chart creation code - Dashboard implementation - Interactive visualizations - Custom plot types - Animation and transitions ### Machine Learning - Data preprocessing - Model training and evaluation - Feature selection - Hyperparameter tuning - Model deployment ### Custom - User-specific requirements - Domain-specific analysis - Integration with existing systems - Performance optimization - Custom algorithms ## Expected Output ### Code Files - generated_code/$1_$2_analysis.py - Main analysis script - generated_code/$1_$2_utils.py - Utility functions - generated_code/$1_$2_config.py - Configuration settings - generated_code/$1_$2_test.py - Unit tests - generated_code/requirements_$1.txt - Dependencies ### Documentation - README.md: Usage instructions and examples - API Documentation: Function and class documentation - Tutorials: Step-by-step guides - Troubleshooting: Common issues and solutions ## Code Quality Standards ### Python Code Standards ```python """ High-quality Python code template for data analysis """ import pandas as pd import numpy as np from typing import Dict, List, Optional import logging from pathlib import Path class DataAnalyzer: """ Data analysis class with comprehensive functionality Args: datapath (str): Path to input data file config (Dict): Configuration parameters Attributes: data (pd.DataFrame): Loaded dataset config (Dict): Configuration settings logger (logging.Logger): Logger instance """ def init(self, datapath: str, config: Dict = None): self.datapath = Path(datapath) self.config = config or {} self.data = None self.logger = self.setuplogger() def setuplogger(self) -> logging.Logger: """Set up logging configuration""" logger = logging.getLogger(name) logger.setLevel(logging.INFO) return logger def load_data(self) -> pd.DataFrame: """ Load data from file with error handling Returns: pd.DataFrame: Loaded dataset Raises: FileNotFoundError: If data file doesn't exist ValueError: If data format is invalid """ try: # Implementation with proper error handling pass except Exception as e: self