Cross Shop Analysis
This module contains the CrossShop class that is used to create a cross-shop diagram.
CrossShop
A class to create a cross-shop diagram.
Source code in pyretailscience/analysis/cross_shop.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
__init__(df, group_1_col, group_1_val, group_2_col, group_2_val, group_3_col=None, group_3_val=None, labels=None, value_col=get_option('column.unit_spend'), agg_func='sum')
Creates a cross-shop diagram that is used to show the overlap of customers between different groups.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame | Table
|
The input DataFrame or ibis Table containing transactional data. |
required |
group_1_col |
str
|
The column name for the first group. |
required |
group_1_val |
str
|
The value of the first group to match. |
required |
group_2_col |
str
|
The column name for the second group. |
required |
group_2_val |
str
|
The value of the second group to match. |
required |
group_3_col |
str
|
The column name for the third group. Defaults to None. |
None
|
group_3_val |
str
|
The value of the third group to match. Defaults to None. |
None
|
labels |
list[str]
|
The labels for the groups. Defaults to None. |
None
|
value_col |
str
|
The column to aggregate. Defaults to the option column.unit_spend. |
get_option('column.unit_spend')
|
agg_func |
str
|
The aggregation function. Defaults to "sum". |
'sum'
|
Returns:
Type | Description |
---|---|
None
|
None |
Raises:
Type | Description |
---|---|
ValueError
|
If the dataframe does not contain the required columns or if the number of labels does not match the number of group indexes given. |
Source code in pyretailscience/analysis/cross_shop.py
plot(title=None, source_text=None, vary_size=False, figsize=None, ax=None, subset_label_formatter=None, **kwargs)
Plot the cross-shop diagram.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
title |
str
|
The title of the plot. Defaults to None. |
None
|
source_text |
str
|
The source text for the plot. Defaults to None. |
None
|
vary_size |
bool
|
Whether to vary the size of the circles based on their values. Defaults to False. |
False
|
figsize |
tuple[int, int]
|
The size of the plot. Defaults to None. |
None
|
ax |
Axes
|
The axes to plot on. Defaults to None. |
None
|
subset_label_formatter |
callable
|
Function to format the subset labels. |
None
|
**kwargs |
dict[str, any]
|
Additional keyword arguments to pass to the diagram. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
SubplotBase |
SubplotBase
|
The axes of the plot. |