File size: 1,167 Bytes
3d13a56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import pandas as pd
import matplotlib.pyplot as plt
import io
from docx import Document
from docx.shared import Inches

def format_indian_units(value):
    """Converts a number to Crores or Lakhs string."""
    try:
        val = float(value)
        if abs(val) >= 10**7:
            return f"{val / 10**7:.2f} Cr"
        elif abs(val) >= 10**5:
            return f"{val / 10**5:.2f} L"
        else:
            return f"{val:,.2f}"
    except (ValueError, TypeError):
        return value

def create_styled_chart(df, title, ylabel, filename):
    """Creates a professional financial chart."""
    plt.figure(figsize=(10, 6))
    plt.style.use('ggplot')
    df.plot(kind='bar', ax=plt.gca())
    plt.title(title, fontsize=14, fontweight='bold')
    plt.ylabel(ylabel)
    plt.xticks(rotation=45)
    plt.tight_layout()
    plt.savefig(filename, dpi=300)
    plt.close()

def add_paragraph_with_insights(doc, heading, content):
    """Adds a heading and a multi-paragraph insight block."""
    doc.add_heading(heading, level=2)
    doc.add_paragraph(content)

# This script can be imported or used as a template by the agent.