Skip to content

feat: convert column names to use the options class #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified data/transactions.parquet
Binary file not shown.
6 changes: 3 additions & 3 deletions docs/analysis_modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ from pyretailscience.standard_graphs import time_plot
rng = np.random.default_rng(42)
df = pd.DataFrame(
{
"transaction_datetime": pd.concat(
"transaction_date": pd.concat(
[pd.Series(pd.date_range(start="2022-01-01", periods=200, freq="D"))] * 3
),
"total_price": np.concatenate(
Expand Down Expand Up @@ -447,8 +447,8 @@ Example:
```python
from pyretailscience import revenue_tree

p1_index = df["transaction_datetime"] < "2023-06-01"
p2_index = df["transaction_datetime"] >= "2023-06-01"
p1_index = df["transaction_date"] < "2023-06-01"
p2_index = df["transaction_date"] >= "2023-06-01"

rev_tree = revenue_tree.RevenueTree(
df=df,
Expand Down
74 changes: 34 additions & 40 deletions docs/examples/cross_shop.ipynb

Large diffs are not rendered by default.

281 changes: 139 additions & 142 deletions docs/examples/gain_loss.ipynb

Large diffs are not rendered by default.

48 changes: 21 additions & 27 deletions docs/examples/product_association.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>transaction_id</th>\n",
" <th>transaction_datetime</th>\n",
" <th>transaction_date</th>\n",
" <th>customer_id</th>\n",
" <th>product_id</th>\n",
" <th>product_name</th>\n",
Expand All @@ -77,9 +77,8 @@
" <th>category_1_id</th>\n",
" <th>brand_name</th>\n",
" <th>brand_id</th>\n",
" <th>unit_price</th>\n",
" <th>quantity</th>\n",
" <th>total_price</th>\n",
" <th>unit_quantity</th>\n",
" <th>unit_spend</th>\n",
" <th>store_id</th>\n",
" </tr>\n",
" </thead>\n",
Expand All @@ -97,7 +96,6 @@
" <td>1</td>\n",
" <td>McFarlane Toys</td>\n",
" <td>3</td>\n",
" <td>27.99</td>\n",
" <td>2</td>\n",
" <td>55.98</td>\n",
" <td>6</td>\n",
Expand All @@ -115,7 +113,6 @@
" <td>53</td>\n",
" <td>Alfred A. Knopf</td>\n",
" <td>264</td>\n",
" <td>10.49</td>\n",
" <td>1</td>\n",
" <td>10.49</td>\n",
" <td>6</td>\n",
Expand All @@ -133,7 +130,6 @@
" <td>21</td>\n",
" <td>AMD</td>\n",
" <td>102</td>\n",
" <td>120.00</td>\n",
" <td>3</td>\n",
" <td>360.00</td>\n",
" <td>4</td>\n",
Expand All @@ -151,7 +147,6 @@
" <td>30</td>\n",
" <td>Pottery Barn</td>\n",
" <td>147</td>\n",
" <td>599.00</td>\n",
" <td>1</td>\n",
" <td>599.00</td>\n",
" <td>4</td>\n",
Expand All @@ -169,7 +164,6 @@
" <td>45</td>\n",
" <td>Pantene</td>\n",
" <td>222</td>\n",
" <td>4.99</td>\n",
" <td>1</td>\n",
" <td>4.99</td>\n",
" <td>4</td>\n",
Expand All @@ -179,12 +173,12 @@
"</div>"
],
"text/plain": [
" transaction_id transaction_datetime customer_id product_id \\\n",
"0 7108 2023-01-12 17:44:29 1 15 \n",
"1 7108 2023-01-12 17:44:29 1 1317 \n",
"2 4553 2023-02-05 09:31:42 1 509 \n",
"3 4553 2023-02-05 09:31:42 1 735 \n",
"4 4553 2023-02-05 09:31:42 1 1107 \n",
" transaction_id transaction_date customer_id product_id \\\n",
"0 7108 2023-01-12 17:44:29 1 15 \n",
"1 7108 2023-01-12 17:44:29 1 1317 \n",
"2 4553 2023-02-05 09:31:42 1 509 \n",
"3 4553 2023-02-05 09:31:42 1 735 \n",
"4 4553 2023-02-05 09:31:42 1 1107 \n",
"\n",
" product_name category_0_name category_0_id \\\n",
"0 Spawn Figure Toys 1 \n",
Expand All @@ -193,19 +187,19 @@
"3 Linden Wood Paneled Mirror Home 5 \n",
"4 Pro-V Daily Moisture Renewal Conditioner Beauty 7 \n",
"\n",
" category_1_name category_1_id brand_name brand_id unit_price \\\n",
"0 Action Figures 1 McFarlane Toys 3 27.99 \n",
"1 Mystery & Thrillers 53 Alfred A. Knopf 264 10.49 \n",
"2 Computer Components 21 AMD 102 120.00 \n",
"3 Home Decor 30 Pottery Barn 147 599.00 \n",
"4 Hair Care 45 Pantene 222 4.99 \n",
" category_1_name category_1_id brand_name brand_id \\\n",
"0 Action Figures 1 McFarlane Toys 3 \n",
"1 Mystery & Thrillers 53 Alfred A. Knopf 264 \n",
"2 Computer Components 21 AMD 102 \n",
"3 Home Decor 30 Pottery Barn 147 \n",
"4 Hair Care 45 Pantene 222 \n",
"\n",
" quantity total_price store_id \n",
"0 2 55.98 6 \n",
"1 1 10.49 6 \n",
"2 3 360.00 4 \n",
"3 1 599.00 4 \n",
"4 1 4.99 4 "
" unit_quantity unit_spend store_id \n",
"0 2 55.98 6 \n",
"1 1 10.49 6 \n",
"2 3 360.00 4 \n",
"3 1 599.00 4 \n",
"4 1 4.99 4 "
]
},
"execution_count": null,
Expand Down
57 changes: 25 additions & 32 deletions docs/examples/retention.ipynb

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions docs/examples/revenue_tree.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>transaction_id</th>\n",
" <th>transaction_datetime</th>\n",
" <th>transaction_date</th>\n",
" <th>customer_id</th>\n",
" <th>product_id</th>\n",
" <th>product_name</th>\n",
Expand Down Expand Up @@ -148,12 +148,12 @@
"</div>"
],
"text/plain": [
" transaction_id transaction_datetime customer_id product_id \\\n",
"0 7108 2023-01-12 17:44:29 1 15 \n",
"1 7108 2023-01-12 17:44:29 1 1317 \n",
"2 4553 2023-02-05 09:31:42 1 509 \n",
"3 4553 2023-02-05 09:31:42 1 735 \n",
"4 4553 2023-02-05 09:31:42 1 1107 \n",
" transaction_id transaction_date customer_id product_id \\\n",
"0 7108 2023-01-12 17:44:29 1 15 \n",
"1 7108 2023-01-12 17:44:29 1 1317 \n",
"2 4553 2023-02-05 09:31:42 1 509 \n",
"3 4553 2023-02-05 09:31:42 1 735 \n",
"4 4553 2023-02-05 09:31:42 1 1107 \n",
"\n",
" product_name category_0_name category_0_id \\\n",
"0 Spawn Figure Toys 1 \n",
Expand Down Expand Up @@ -334,8 +334,8 @@
"source": [
"from pyretailscience import revenue_tree\n",
"\n",
"p1_index = df[\"transaction_datetime\"] < \"2023-06-01\"\n",
"p2_index = df[\"transaction_datetime\"] >= \"2023-06-01\"\n",
"p1_index = df[\"transaction_date\"] < \"2023-06-01\"\n",
"p2_index = df[\"transaction_date\"] >= \"2023-06-01\"\n",
"\n",
"rev_tree = revenue_tree.RevenueTree(\n",
" df=df,\n",
Expand Down Expand Up @@ -554,7 +554,7 @@
"</svg>\n"
],
"text/plain": [
"<graphviz.graphs.Digraph at 0x7fc8d39c0760>"
"<graphviz.graphs.Digraph at 0x7fe37f36b070>"
]
},
"execution_count": null,
Expand Down
84 changes: 42 additions & 42 deletions docs/examples/segmentation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>transaction_id</th>\n",
" <th>transaction_datetime</th>\n",
" <th>transaction_date</th>\n",
" <th>customer_id</th>\n",
" <th>product_id</th>\n",
" <th>product_name</th>\n",
Expand Down Expand Up @@ -150,12 +150,12 @@
"</div>"
],
"text/plain": [
" transaction_id transaction_datetime customer_id product_id \\\n",
"0 7108 2023-01-12 17:44:29 1 15 \n",
"1 7108 2023-01-12 17:44:29 1 1317 \n",
"2 4553 2023-02-05 09:31:42 1 509 \n",
"3 4553 2023-02-05 09:31:42 1 735 \n",
"4 4553 2023-02-05 09:31:42 1 1107 \n",
" transaction_id transaction_date customer_id product_id \\\n",
"0 7108 2023-01-12 17:44:29 1 15 \n",
"1 7108 2023-01-12 17:44:29 1 1317 \n",
"2 4553 2023-02-05 09:31:42 1 509 \n",
"3 4553 2023-02-05 09:31:42 1 735 \n",
"4 4553 2023-02-05 09:31:42 1 1107 \n",
"\n",
" product_name category_0_name category_0_id \\\n",
"0 Spawn Figure Toys 1 \n",
Expand Down Expand Up @@ -356,7 +356,7 @@
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>transaction_id</th>\n",
" <th>transaction_datetime</th>\n",
" <th>transaction_date</th>\n",
" <th>customer_id</th>\n",
" <th>product_id</th>\n",
" <th>product_name</th>\n",
Expand Down Expand Up @@ -468,12 +468,12 @@
"</div>"
],
"text/plain": [
" transaction_id transaction_datetime customer_id product_id \\\n",
"0 7108 2023-01-12 17:44:29 1 15 \n",
"1 7108 2023-01-12 17:44:29 1 1317 \n",
"2 4553 2023-02-05 09:31:42 1 509 \n",
"3 4553 2023-02-05 09:31:42 1 735 \n",
"4 4553 2023-02-05 09:31:42 1 1107 \n",
" transaction_id transaction_date customer_id product_id \\\n",
"0 7108 2023-01-12 17:44:29 1 15 \n",
"1 7108 2023-01-12 17:44:29 1 1317 \n",
"2 4553 2023-02-05 09:31:42 1 509 \n",
"3 4553 2023-02-05 09:31:42 1 735 \n",
"4 4553 2023-02-05 09:31:42 1 1107 \n",
"\n",
" product_name category_0_name category_0_id \\\n",
"0 Spawn Figure Toys 1 \n",
Expand Down Expand Up @@ -556,6 +556,20 @@
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Total</td>\n",
" <td>8.908818e+07</td>\n",
" <td>25490</td>\n",
" <td>4250</td>\n",
" <td>223950</td>\n",
" <td>20961.925033</td>\n",
" <td>3495.024770</td>\n",
" <td>5.997647</td>\n",
" <td>397.803891</td>\n",
" <td>8.785798</td>\n",
" <td>1.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Light</td>\n",
" <td>1.344912e+07</td>\n",
" <td>7054</td>\n",
Expand All @@ -569,7 +583,7 @@
" <td>0.5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <th>2</th>\n",
" <td>Heavy</td>\n",
" <td>4.518138e+07</td>\n",
" <td>8572</td>\n",
Expand All @@ -583,7 +597,7 @@
" <td>0.2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <th>3</th>\n",
" <td>Medium</td>\n",
" <td>3.045768e+07</td>\n",
" <td>9864</td>\n",
Expand All @@ -596,42 +610,28 @@
" <td>8.806671</td>\n",
" <td>0.3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Total</td>\n",
" <td>8.908818e+07</td>\n",
" <td>25490</td>\n",
" <td>4250</td>\n",
" <td>223950</td>\n",
" <td>20961.925033</td>\n",
" <td>3495.024770</td>\n",
" <td>5.997647</td>\n",
" <td>397.803891</td>\n",
" <td>8.785798</td>\n",
" <td>1.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" segment_name spend transactions customers units \\\n",
"0 Light 1.344912e+07 7054 2125 56523 \n",
"1 Heavy 4.518138e+07 8572 850 80558 \n",
"2 Medium 3.045768e+07 9864 1275 86869 \n",
"3 Total 8.908818e+07 25490 4250 223950 \n",
"0 Total 8.908818e+07 25490 4250 223950 \n",
"1 Light 1.344912e+07 7054 2125 56523 \n",
"2 Heavy 4.518138e+07 8572 850 80558 \n",
"3 Medium 3.045768e+07 9864 1275 86869 \n",
"\n",
" spend_per_customer spend_per_transaction transactions_per_customer \\\n",
"0 6328.995732 1906.594263 3.319529 \n",
"1 53154.567635 5270.809903 10.084706 \n",
"2 23888.378800 3087.761858 7.736471 \n",
"3 20961.925033 3495.024770 5.997647 \n",
"0 20961.925033 3495.024770 5.997647 \n",
"1 6328.995732 1906.594263 3.319529 \n",
"2 53154.567635 5270.809903 10.084706 \n",
"3 23888.378800 3087.761858 7.736471 \n",
"\n",
" price_per_unit units_per_transaction customers_pct \n",
"0 237.940589 8.012900 0.5 \n",
"1 560.855315 9.397807 0.2 \n",
"2 350.616249 8.806671 0.3 \n",
"3 397.803891 8.785798 1.0 "
"0 397.803891 8.785798 1.0 \n",
"1 237.940589 8.012900 0.5 \n",
"2 560.855315 9.397807 0.2 \n",
"3 350.616249 8.806671 0.3 "
]
},
"execution_count": null,
Expand Down
Loading