Python Code

Nebula Writer can use Python as a local analysis tool for spreadsheets, CSVs, charts, generated documents, and reproducible examples.


When to Use This Page

  • You want to analyze data inside a writing project
  • You need charts, tables, or summaries for a report
  • You want the assistant to produce Python that you can inspect
  • You work with Excel, CSV, DOCX, PPTX, or PDF artifacts

How Python Fits Into Nebula Writer

Python runs against files in your project folder. That means generated charts, cleaned data, and exported artifacts can live next to the draft, paper, spreadsheet, or slide deck that uses them.

Typical uses:

  • Read a CSV or Excel workbook
  • Summarize columns with pandas
  • Generate a chart image
  • Create a cleaned workbook
  • Produce a table for Markdown or LaTeX
  • Generate a DOCX or PPTX artifact from structured data

Example Workspace

Nebula Writer workspace with Markdown source and preview
Nebula Writer workspace with Markdown source and preview

Keep scripts in a folder such as analysis/ and generated outputs in folders such as figures/, tables/, or exports/.

project/
  research/
    paper.tex
    research-brief.md
  office/
    research-dashboard.xlsx
  analysis/
    summarize_dashboard.py
  figures/
    dashboard-summary.png

Read Excel with pandas

import pandas as pd

df = pd.read_excel("office/research-dashboard.xlsx", sheet_name="Data")
print(df.head())
print(df.describe(include="all"))

Use this when you want the assistant to inspect data before changing prose.

Read analysis/summarize_dashboard.py and office/research-dashboard.xlsx. Explain what the script does and suggest one chart for the Results section.

Create a Chart

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_excel("office/research-dashboard.xlsx", sheet_name="Data")

ax = df.groupby("Category")["Amount"].sum().sort_values().plot(kind="barh")
ax.set_title("Budget by category")
ax.set_xlabel("Amount")

plt.tight_layout()
plt.savefig("figures/budget-by-category.png", dpi=200)

Then reference the chart from Markdown or LaTeX:

![Budget by category](../figures/budget-by-category.png)
\begin{figure}
  \centering
  \includegraphics[width=.8\linewidth]{figures/budget-by-category.png}
  \caption{Budget by category.}
\end{figure}

Create an Excel Output

Use openpyxl or xlsxwriter when the output should remain editable in Excel.

import pandas as pd

df = pd.read_excel("office/research-dashboard.xlsx", sheet_name="Data")
summary = df.groupby("Category", as_index=False)["Amount"].sum()

with pd.ExcelWriter("exports/category-summary.xlsx", engine="xlsxwriter") as writer:
    summary.to_excel(writer, sheet_name="Summary", index=False)

Open the generated workbook in Nebula Writer to inspect it alongside your draft.


Create a PowerPoint Draft

Use python-pptx for a first pass when data needs to become a deck.

from pptx import Presentation
from pptx.util import Inches

prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[5])
slide.shapes.title.text = "Research dashboard summary"

box = slide.shapes.add_textbox(Inches(1), Inches(1.5), Inches(8), Inches(2))
box.text_frame.text = "Key finding: budget risk is concentrated in three categories."

prs.save("exports/dashboard-summary.pptx")

Then open the .pptx in Nebula Writer for slide review and editing.


Create a DOCX Report

Use python-docx when you want a generated report that can still be edited as a Word document.

from docx import Document

doc = Document()
doc.add_heading("Research Dashboard Summary", level=1)
doc.add_paragraph("This draft was generated from the project workbook.")
doc.add_heading("Key risks", level=2)
doc.add_paragraph("Review categories with the largest variance before publishing.")
doc.save("exports/dashboard-summary.docx")

Useful Libraries

Common Python libraries available for analysis workflows include:

LibraryUse
pandasTables, CSV, Excel, grouping, summaries
numpyNumeric arrays and calculations
scipyScientific calculations
matplotlibCharts and figures
seabornStatistical visualization
scikit-learnModeling and clustering
PillowImage processing
openpyxlExcel workbook reading and writing
xlsxwriterExcel output formatting
python-docxDOCX generation
python-pptxPPTX generation
reportlab / fpdf2PDF generation
requestsHTTP data access

Prompt Examples

Write a Python script that reads @research-dashboard.xlsx and saves a chart to figures/.
Explain this Python script and tell me which output files it creates.
Create a cleaned CSV from this workbook, but do not overwrite the original.
Use Python to generate a one-slide PPTX summary from the spreadsheet.

Safety Tips

  • Keep generated files in exports/, figures/, or tables/
  • Do not overwrite original data unless you asked for it explicitly
  • Ask the assistant to show the script before running a destructive operation
  • Review generated charts before inserting them into a paper or deck
  • Keep scripts committed with the draft when reproducibility matters