Back to guides
Data AnalysisAI ToolsBusiness Intelligence

AI-Powered Data Analysis: From Spreadsheets to Insights

212AY Team·2026-04-20·11 min
import pandas as pd
import matplotlib.pyplot as plt
from openai import OpenAI

client = OpenAI()

def analyze_dataframe(df, question):
    # Get dataframe info
    info = f"Columns: {list(df.columns)}\n"
    info += f"Shape: {df.shape}\n"
    info += f"Sample:\n{df.head().to_string()}"
    
    response = client.chat.completions.create(
        model="gpt-4",
        messages=[
            {"role": "system", "content": "Analyze this data and answer the question. Include Python code if relevant."},
            {"role": "user", "content": f"Data:\n{info}\n\nQuestion: {question}"}
        ]
    )
    return response.choices[0].message.content

Use Case: Moroccan E-commerce

A small business in Marrakech used AI to analyze their sales data and discovered:

  • 60% of revenue came from returning customers (not new)
  • Their best-selling products had predictable seasonal dips
  • WhatsApp was their most effective marketing channel

They adjusted their strategy and increased revenue by 35% in one quarter.

Related Guides

AI-Powered Marketing Automation: A Complete Walkthrough

Learn how to automate your marketing with AI: email campaigns, social media content generation, ad optimization, and customer segmentation.

Using AI as an Educator or Tutor: A Practical Guide

How teachers and tutors can leverage AI tools to create personalized learning experiences, automate grading, and enhance student engagement.