Explore a CSV

Runs in your browserBrowser compatible

Find missing values, see which region and category earn the most, and export the result. Start on sample sales data or your own CSV.

Run it

What you get: revenue by region

regionordersunitsestimated_revenue
South13822,349.70
North19902,298.29
East16752,171.31
West12571,954.19

Output of the revenue-by-region cell on the sample data.csv (60 orders).

The notebook

A read-only preview. Nothing here runs.

  1. # Explore a CSV Go from a raw CSV to a ranked, charted answer: check data quality, work out revenue by region and category, and export the result. It opens on a sample `data.csv` of 60 orders. To use your own file, drop a CSV (up to 4 MB) onto the file list on the left, or use **+** then **Import CSV**, and the next cell switches to it; re-run from there. Your file stays in this browser tab; it is sent to ByteRun only if you sign up and carry this project over.

  2. import pandas as pd
    
    PATH = "data.csv"  # set automatically when you upload a CSV
    df = pd.read_csv(PATH)
    if df.empty:
        raise ValueError(f"{PATH} has no data rows")
    
    print(f"Loaded {len(df):,} rows and {len(df.columns)} columns.")
    
    
    def download_link(data, filename, mime):
        # A link that saves `data` as a file, so a result can leave the notebook without any server.
        from base64 import b64encode
        from IPython.display import HTML
        return HTML(f'<a download="{filename}" href="data:{mime};base64,{b64encode(data).decode()}">Download {filename}</a>')
    
    
    df.head()
  3. ## Check data quality Look before you clean: nothing is dropped or changed here.

  4. quality = pd.DataFrame({
        "dtype": df.dtypes.astype(str),
        "missing": df.isna().sum(),
        "missing_%": (df.isna().mean() * 100).round(1),
        "unique": df.nunique(),
    }).sort_values("missing_%", ascending=False)
    
    print(f"Duplicate rows: {df.duplicated().sum()}")
    quality
  5. ## Summarize the columns Numbers and categories read differently, so they get separate summaries.

  6. df.describe().T
  7. for col in df.select_dtypes(exclude="number").columns:
        print(df[col].value_counts().to_string(), "\n")
  8. ## Answer a question: which region earns the most? `estimated_revenue` is `units ร— unit_price` per row. It is an estimate: the sample has no discounts, returns or order status.

  9. df["estimated_revenue"] = df["units"] * df["unit_price"]
    
    by_region = (
        df.groupby("region", as_index=False)
          .agg(orders=("order_id", "nunique"),
               units=("units", "sum"),
               estimated_revenue=("estimated_revenue", "sum"))
          .sort_values("estimated_revenue", ascending=False)
          .round(2)
    )
    by_region
  10. import io
    
    import matplotlib.pyplot as plt
    
    by_category = df.groupby("category")["estimated_revenue"].sum().sort_values(ascending=False)
    
    fig, axes = plt.subplots(1, 2, figsize=(11, 4))
    by_region.plot.bar(x="region", y="estimated_revenue", legend=False, ax=axes[0], title="Estimated revenue by region")
    by_category.plot.bar(ax=axes[1], title="Estimated revenue by category")
    for ax in axes:
        ax.set_ylabel("Estimated revenue")
    plt.tight_layout()
    plt.show()
    
    top = by_region.iloc[0]
    print(f"{top.region} leads with {top.estimated_revenue:,.2f} ({top.estimated_revenue / by_region.estimated_revenue.sum():.0%} of the total).")
    
    buf = io.BytesIO()
    fig.savefig(buf, format="png", dpi=150)
    download_link(buf.getvalue(), "revenue.png", "image/png")
  11. by_region.to_csv("revenue_by_region.csv", index=False)
    print("Saved revenue_by_region.csv to the project files.")
    download_link(by_region.to_csv(index=False).encode(), "revenue_by_region.csv", "text/csv")
  12. ## Your turn 1. Which category earns the most in the top region? 2. Which single order has the highest `estimated_revenue`? 3. Swap `PATH` for your own CSV and re-run the quality check.

Runtime requirements

Python
Python 3.12 (in-browser) or the Python data science environment
Packages
pandas, matplotlib
Sample data
data.csv
Environment
Python data science ยท CPU

Browser or real compute

In your browser this notebook runs on a small Python with limited memory and no installs. A ByteRun project runs the same notebook on a full machine with your files saved, any package, and more memory when you need it.

Start the 60-day free trial with this template