1import marimo
2
3__generated_with = "0.13.0"
4app = marimo.App()
5
6
7@app.cell
8def intro():
9 import marimo as mo
10 mo.md("""
11 # Data Analysis
12
13 a marimo notebook demonstrating data processing with explicit dependencies between cells.
14 """)
15 return (mo,)
16
17
18@app.cell
19def load_data():
20 import pandas as pd
21
22 df = pd.DataFrame({
23 "city": ["Dublin", "Berlin", "Paris", "Amsterdam", "Lisbon", "Vienna", "Prague", "Warsaw"],
24 "population_m": [1.4, 3.7, 2.2, 0.9, 0.5, 1.9, 1.3, 1.8],
25 "area_km2": [115, 892, 105, 219, 100, 415, 496, 517],
26 "founded": [841, 1237, 250, 1275, 1200, 881, 885, 1300],
27 })
28 return (df,)
29
30
31@app.cell
32def compute_density(df):
33 df["density"] = (df["population_m"] * 1_000_000 / df["area_km2"]).round(0).astype(int)
34 df["age"] = 2026 - df["founded"]
35 return (df,)
36
37
38@app.cell
39def top_cities(df):
40 top = df.sort_values("density", ascending=False).head(3)
41 print("densest cities:")
42 for _, row in top.iterrows():
43 print(f" {row['city']}: {row['density']} people/km2")
44 return (top,)
45
46
47@app.cell
48def summary(df, top):
49 total_pop = df["population_m"].sum()
50 oldest = df.sort_values("age", ascending=False).iloc[0]
51 print(f"total population: {total_pop:.1f}M across {len(df)} cities")
52 print(f"oldest city: {oldest['city']} ({oldest['age']} years)")
53 print(f"top 3 densest account for {top['population_m'].sum():.1f}M people")
54 return ()
55
56
57if __name__ == "__main__":
58 app.run()