Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/machow/coffee-sales-data
https://github.com/machow/coffee-sales-data
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/machow/coffee-sales-data
- Owner: machow
- License: mit
- Created: 2024-05-13T21:20:59.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-05-16T19:48:05.000Z (8 months ago)
- Last Synced: 2024-05-16T20:59:59.500Z (8 months ago)
- Language: Jupyter Notebook
- Size: 936 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Coffee sales data
This repository generates sales data for a fictitious coffee device
store.Here are some useful pieces:
- [example_notebook.ipynb](./example_notebook.ipynb): jupyter notebook
example.
- [README.qmd](./README.qmd): the [quarto](https://quarto.org) document
which generated this page.
- [Great Tables](https://github.com/posit-dev/great-tables): python
library making the beautiful tables.## What can I do with it?
This repo is used to generate this table for the Great Tables examples
gallery (scroll down for code):![An image of a Great Table output, which is an HTML table. Each row is
a coffee product](./data/coffee-table.png)## Code for table
``` python
import polars as pl
import polars.selectors as cs
from great_tables import GT, loc, stylecoffee_sales = pl.read_json("data/coffee-sales.json")
`````` python
sel_rev = cs.starts_with("revenue")
sel_prof = cs.starts_with("profit")coffee_table = (
GT(coffee_sales)
.tab_header("Sales of Coffee Equipment")
.tab_spanner(label="Revenue", columns=sel_rev)
.tab_spanner(label="Profit", columns=sel_prof)
.cols_label(
revenue_dollars="Amount",
profit_dollars="Amount",
revenue_pct="Percent",
profit_pct="Percent",
monthly_sales="Monthly Sales",
icon="",
product="Product",
)
# formatting ----
.fmt_number(
columns=cs.ends_with("dollars"),
compact=True,
pattern="${x}",
n_sigfig=3,
)
.fmt_percent(columns=cs.ends_with("pct"), decimals=0)
# style ----
.tab_style(
style=style.fill(color="aliceblue"),
locations=loc.body(columns=sel_rev),
)
.tab_style(
style=style.fill(color="papayawhip"),
locations=loc.body(columns=sel_prof),
)
.tab_style(
style=style.text(weight="bold"),
locations=loc.body(rows=pl.col("product") == "Total"),
)
.fmt_nanoplot("monthly_sales", plot_type="bar")
.fmt_image("icon", path="assets")
.sub_missing(missing_text="")
)coffee_table.save("data/coffee-table.png", scale=2)
```See this [example_notebook.ipynb](./example_notebook.ipynb) for this
code in jupyter notebook form.## Regenerating data and README
``` bash
# generate data ----
python 1-generate.py# generate README.md ----
quarto render README.qmd# or to do everything in one command
make all
```