pandas-plots 0.9.6__tar.gz → 0.9.7__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pandas-plots
3
- Version: 0.9.6
3
+ Version: 0.9.7
4
4
  Summary: A collection of helper for table handling and vizualization
5
5
  Home-page: https://github.com/smeisegeier/pandas-plots
6
6
  Author: smeisegeier
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = pandas-plots
3
- version = 0.9.6
3
+ version = 0.9.7
4
4
  author = smeisegeier
5
5
  author_email = dexterDSDo@googlemail.com
6
6
  description = A collection of helper for table handling and vizualization
@@ -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(" Not a valid URL")
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_
@@ -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]
@@ -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 (
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pandas-plots
3
- Version: 0.9.6
3
+ Version: 0.9.7
4
4
  Summary: A collection of helper for table handling and vizualization
5
5
  Home-page: https://github.com/smeisegeier/pandas-plots
6
6
  Author: smeisegeier
File without changes
File without changes