pandas-plots 0.9.6__py3-none-any.whl → 0.9.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pandas_plots/hlp.py +42 -3
- pandas_plots/pls.py +5 -0
- pandas_plots/tbl.py +2 -2
- {pandas_plots-0.9.6.dist-info → pandas_plots-0.9.7.dist-info}/METADATA +1 -1
- pandas_plots-0.9.7.dist-info/RECORD +9 -0
- pandas_plots-0.9.6.dist-info/RECORD +0 -9
- {pandas_plots-0.9.6.dist-info → pandas_plots-0.9.7.dist-info}/LICENSE +0 -0
- {pandas_plots-0.9.6.dist-info → pandas_plots-0.9.7.dist-info}/WHEEL +0 -0
- {pandas_plots-0.9.6.dist-info → pandas_plots-0.9.7.dist-info}/top_level.txt +0 -0
pandas_plots/hlp.py
CHANGED
@@ -179,15 +179,23 @@ def create_barcode_from_url(
|
|
179
179
|
output_path: str | None = None,
|
180
180
|
show_image: bool = False,
|
181
181
|
):
|
182
|
+
"""
|
183
|
+
Create a barcode from the given URL. Uses "QR Code" from DENSO WAVE INCORPORATED.
|
184
|
+
|
185
|
+
Args:
|
186
|
+
url (str): The URL to encode in the barcode.
|
187
|
+
output_path (str | None, optional): The path to save the barcode image. Defaults to None.
|
188
|
+
show_image (bool, optional): Whether to display the barcode image. Defaults to False.
|
189
|
+
"""
|
182
190
|
WIDTH = 400
|
183
191
|
HEIGHT = 400
|
184
192
|
|
185
193
|
if not re.match(URL_REGEX, url):
|
186
|
-
print("
|
187
|
-
return
|
194
|
+
print("💡 Not a valid URL")
|
188
195
|
|
189
196
|
image = requests.get(
|
190
|
-
f"https://chart.googleapis.com/chart?chs={WIDTH}x{HEIGHT}&cht=qr&chl={url}"
|
197
|
+
# f"https://chart.googleapis.com/chart?chs={WIDTH}x{HEIGHT}&cht=qr&chl={url}"
|
198
|
+
f"https://api.qrserver.com/v1/create-qr-code/?size={WIDTH}x{HEIGHT}&data={url}"
|
191
199
|
)
|
192
200
|
image.raise_for_status()
|
193
201
|
|
@@ -202,3 +210,34 @@ def create_barcode_from_url(
|
|
202
210
|
plt.imshow(img)
|
203
211
|
# plt.axis('off') # Turn off axis numbers
|
204
212
|
plt.show()
|
213
|
+
|
214
|
+
def add_datetime_columns(df: pd.DataFrame, date_column: str = None) -> pd.DataFrame:
|
215
|
+
if not date_column:
|
216
|
+
date_column = [col for col in df.columns if pd.api.types.is_datetime64_any_dtype(df[col])][0]
|
217
|
+
|
218
|
+
if not date_column or not pd.api.types.is_datetime64_any_dtype(df[date_column]):
|
219
|
+
print("❌ No datetime column found")
|
220
|
+
return
|
221
|
+
|
222
|
+
if [col for col in df.columns if "YYYY-WW" in col]:
|
223
|
+
print("❌ Added datetime columns already exist")
|
224
|
+
return
|
225
|
+
|
226
|
+
print(f"⏳ Adding datetime columns basing off of: {date_column}")
|
227
|
+
df_= df.copy()
|
228
|
+
|
229
|
+
df_[date_column] = pd.to_datetime(df_[date_column])
|
230
|
+
|
231
|
+
df_["YYYY"] = df_[date_column].dt.year
|
232
|
+
df_["MM"] = df_[date_column].dt.month
|
233
|
+
df_["Q"] = df_[date_column].dt.quarter
|
234
|
+
|
235
|
+
df_["YYYY-MM"] = df_[date_column].dt.to_period("M").astype(str)
|
236
|
+
df_["YYYYQ"] = df_[date_column].dt.to_period("Q").astype(str)
|
237
|
+
df_["YYYY-WW"] = (
|
238
|
+
df_[date_column].dt.isocalendar().year.astype(str) + "-" +
|
239
|
+
df_[date_column].dt.isocalendar().week.astype(str).str.zfill(2)
|
240
|
+
)
|
241
|
+
df_["DDD"] = df_[date_column].dt.weekday.map({0: "Mon", 1: "Tue", 2: "Wed", 3: "Thu", 4: "Fri", 5: "Sat", 6: "Sun"})
|
242
|
+
|
243
|
+
return df_
|
pandas_plots/pls.py
CHANGED
@@ -111,6 +111,7 @@ def plot_stacked_bars(
|
|
111
111
|
caption: str = None,
|
112
112
|
sort_values: bool = False,
|
113
113
|
show_total: bool = False,
|
114
|
+
precision: int = 0,
|
114
115
|
) -> None:
|
115
116
|
"""
|
116
117
|
Generates a stacked bar plot using the provided DataFrame.
|
@@ -135,6 +136,7 @@ def plot_stacked_bars(
|
|
135
136
|
- caption: An optional string indicating the caption for the chart.
|
136
137
|
- sort_values: bool = False - Sort axis by index (default) or values
|
137
138
|
- show_total: bool = False - Whether to show the total value
|
139
|
+
- precision: int = 0 - The number of decimal places to round to
|
138
140
|
|
139
141
|
Returns:
|
140
142
|
None
|
@@ -166,6 +168,9 @@ def plot_stacked_bars(
|
|
166
168
|
df.iloc[:, 0] = df.iloc[:, 0].str.strip()
|
167
169
|
if df.iloc[:, 1].dtype.kind == "O":
|
168
170
|
df.iloc[:, 1] = df.iloc[:, 1].str.strip()
|
171
|
+
|
172
|
+
# * apply precision
|
173
|
+
df.iloc[:,2] = df.iloc[:,2].round(precision)
|
169
174
|
|
170
175
|
# * set index + color col
|
171
176
|
col_index = df.columns[0] if not swap else df.columns[1]
|
pandas_plots/tbl.py
CHANGED
@@ -15,9 +15,9 @@ from scipy import stats
|
|
15
15
|
|
16
16
|
from .hlp import wrap_text
|
17
17
|
# from devtools import debug
|
18
|
+
pd.options.display.colheader_justify = "right"
|
18
19
|
# pd.options.mode.chained_assignment = None
|
19
20
|
|
20
|
-
|
21
21
|
TOTAL_LITERAL = Literal[
|
22
22
|
"sum", "mean", "median", "min", "max", "std", "var", "skew", "kurt"
|
23
23
|
]
|
@@ -363,7 +363,7 @@ def show_num_df(
|
|
363
363
|
"""
|
364
364
|
# * ensure arguments match parameter definition
|
365
365
|
if any([df[col].dtype.kind not in ["i", "u", "f"] for col in df.columns]) == True:
|
366
|
-
print(f"❌ table must contain numeric data only")
|
366
|
+
print(f"❌ table must contain numeric data only. Maybe you forgot to convert this table with pivot or pivot_table first?")
|
367
367
|
return
|
368
368
|
|
369
369
|
if (
|
@@ -0,0 +1,9 @@
|
|
1
|
+
pandas_plots/hlp.py,sha256=ZgdfFO9pnEtNyHItzbQmntQF5cr66MLsnvlFj2vlSsE,8490
|
2
|
+
pandas_plots/pls.py,sha256=zp9GBNcCi1UBy0X1yrZMYQGtYmRflWcbSWZZCPr537E,28671
|
3
|
+
pandas_plots/tbl.py,sha256=BaAGZmoF6DDxnN2lyG9-qIE-6Rvpny9mKECH2LJOLJg,22775
|
4
|
+
pandas_plots/ven.py,sha256=nDKS7cTIHOJhIXKnAxAkEoqPgVZCUPJld5CvSiB2JC4,11721
|
5
|
+
pandas_plots-0.9.7.dist-info/LICENSE,sha256=6KQ5KVAAhRaB-JJKpX4cefKvRZRgI7GUPc92_2d31XY,1051
|
6
|
+
pandas_plots-0.9.7.dist-info/METADATA,sha256=KBgqxvFa5tw0hxG2pFpRFKogkASXPxwYL_QRhoMudtw,6259
|
7
|
+
pandas_plots-0.9.7.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
8
|
+
pandas_plots-0.9.7.dist-info/top_level.txt,sha256=XnaNuIHBqMmCeh_U7nKOYTwFue_SIA0wxuDgdPmnnSk,13
|
9
|
+
pandas_plots-0.9.7.dist-info/RECORD,,
|
@@ -1,9 +0,0 @@
|
|
1
|
-
pandas_plots/hlp.py,sha256=ZxtK1phBO7VZrTQ6mFbNRQCz-WfIqmTk2yAPli1ukhY,6838
|
2
|
-
pandas_plots/pls.py,sha256=Asstu3RWGdbuqo5WW6Om2sJkV5KUP1vwlr4Vu2q5I9c,28501
|
3
|
-
pandas_plots/tbl.py,sha256=QxeXh5Hip3s_F91P89t0wLJK5RnLhFMBMNsCgkl6bWg,22656
|
4
|
-
pandas_plots/ven.py,sha256=nDKS7cTIHOJhIXKnAxAkEoqPgVZCUPJld5CvSiB2JC4,11721
|
5
|
-
pandas_plots-0.9.6.dist-info/LICENSE,sha256=6KQ5KVAAhRaB-JJKpX4cefKvRZRgI7GUPc92_2d31XY,1051
|
6
|
-
pandas_plots-0.9.6.dist-info/METADATA,sha256=cjaDV6sPsgeN22UP5hpSaxJqmKVNCdWj7iwyfYifluc,6259
|
7
|
-
pandas_plots-0.9.6.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
8
|
-
pandas_plots-0.9.6.dist-info/top_level.txt,sha256=XnaNuIHBqMmCeh_U7nKOYTwFue_SIA0wxuDgdPmnnSk,13
|
9
|
-
pandas_plots-0.9.6.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|