summaryrefslogtreecommitdiff
path: root/python-df2img.spec
blob: fc62d647dc10b22bf3509c35dde6b439c4913cc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
%global _empty_manifest_terminate_build 0
Name:		python-df2img
Version:	0.2.11
Release:	1
Summary:	Save a Pandas DataFrame as image
License:	MIT
URL:		https://df2img.dev
Source0:	https://mirrors.aliyun.com/pypi/web/packages/60/b9/0526a8ebe08fe11824806ee5c37ff8480fec791cfd34278ea2981273f9b7/df2img-0.2.11.tar.gz
BuildArch:	noarch

Requires:	python3-kaleido
Requires:	python3-pandas
Requires:	python3-plotly

%description
# df2img: Save a Pandas DataFrame as image

![img](https://img.shields.io/pypi/v/df2img)
![img](https://img.shields.io/pypi/pyversions/df2img)
![img](https://img.shields.io/github/license/andreas-vester/df2img)
![img](https://img.shields.io/github/issues/andreas-vester/df2img)
![img](https://img.shields.io/github/stars/andreas-vester/df2img)

## What is it all about?

Have you ever tried to save a ``pd.DataFrame`` into an image file? This is not a straightforward process at all. Unfortunately, ``pandas`` itself doesn't provide this functionality out of the box.

**df2img** tries to fill the gap. It is a Python library that greatly simplifies the process of saving a ``pd.DataFrame`` into an image file (e.g. ``png`` or ``jpg``).

It is a wrapper/convenience function in order to create a ``plotly`` Table. That is, one can use ``plotly``'s styling function to format the table.


## Dependencies

**df2img** has a limited number of dependencies, namely

- ``pandas``
- ``plotly``
- ``kaleido``


## Documentation

An extensive documentation is available at https://df2img.dev.


## Quickstart

You can install the package via ``pip``.

```bash
pip install df2img
```

Using ``poetry``?

```bash
poetry add df2img
```

Let's create a simple ``pd.DataFrame`` with some dummy data:

```python
import pandas as pd

import df2img

df = pd.DataFrame(
    data=dict(
        float_col=[1.4, float("NaN"), 250, 24.65],
        str_col=("string1", "string2", float("NaN"), "string4"),
    ),
    index=["row1", "row2", "row3", "row4"],
)
```
```python
      float_col  str_col
row1       1.40  string1
row2        NaN  string2
row3     250.00      NaN
row4      24.65  string4
```

### Basics

Saving ``df`` into a png-file now takes just two lines of code including some styling out of the box.

* First, we create a ``plotly`` figure.
* Second, we save the figure to disk.

```python
fig = df2img.plot_dataframe(df, fig_size=(500, 140))

df2img.save_dataframe(fig=fig, filename="plot1.png")
```

![img](https://github.com/andreas-vester/df2img/blob/main/docs/img/plot1.png?raw=true)


### Formatting

You can control the settings for the header row via the ``tbl_header`` input argument. This accepts a regular ``dict``. This ``dict`` can comprise various key/value pairs that are also accepted by ``plotly``. All available key/value pairs can be seen at ``plotly``'s website at https://plotly.com/python/reference/table/#table-header.

Let's set the header row in a different color and size. Also, let's set the alignment to "left".

```python
fig = df2img.plot_dataframe(
    df,
    tbl_header=dict(
        align="left",
        fill_color="blue",
        font_color="white",
        font_size=14,
    ),
    fig_size=(500, 140),
)
```
![img](https://github.com/andreas-vester/df2img/blob/main/docs/img/plot2.png?raw=true)


Controlling the table body (cells) is basically the same. Just use the ``tbl_cells`` input argument, which happens to be a ``dict``, too.
See https://plotly.com/python/reference/table/#table-cells for all the possible key/value pairs.

Let's print the table cell values in yellow on a green background and align them "right".

```python
fig = df2img.plot_dataframe(
    df,
    tbl_cells=dict(
        align="right",
        fill_color="green",
        font_color="yellow",
    ),
    fig_size=(500, 140),
)
```

![img](https://github.com/andreas-vester/df2img/blob/main/docs/img/plot3.png?raw=true)


You can alternate row colors for better readability by using the ``row_fill_color`` input argument. Using HEX colors is also possible:

```python
fig = df2img.plot_dataframe(
    df,
    row_fill_color=("#ffffff", "#d7d8d6"),
    fig_size=(500, 140),
)
```

![img](https://github.com/andreas-vester/df2img/blob/main/docs/img/plot4.png?raw=true)


Setting the title will be controlled via the ``title`` input argument. You can find the relevant key/value pairs here: https://plotly.com/python/reference/layout/#layout-title.

Let's put the title in a different font and size. In addition, we can control the alignment via the ``x`` key/value pair. It sets the x (horizontal) position in normalized coordinates from "0" (left) to "1" (right).

```python
  fig = df2img.plot_dataframe(
      df,
      title=dict(
          font_color="darkred",
          font_family="Times New Roman",
          font_size=24,
          text="This is a title starting at the x-value x=0.1",
          x=0.1,
          xanchor="left",
      ),
      fig_size=(500, 140),
  )
  ```

![img](https://github.com/andreas-vester/df2img/blob/main/docs/img/plot5.png?raw=true)


You can also control relative column width via the ``col_width`` argument. Let's set the first column's width triple the width of the third column and the second column's width double the width of the third column.

```python
fig = df2img.plot_dataframe(
    df,
    col_width=[3, 2, 1],
    fig_size=(500, 140),
)
```

![img](https://github.com/andreas-vester/df2img/blob/main/docs/img/plot6.png?raw=true)

## Contributing to df2img

If you consider to contribute to **df2img**, please read the [Contributing to df2img](./CONTRIBUTING.md) section in the documentation. This document is supposed to guide you through the whole process.


%package -n python3-df2img
Summary:	Save a Pandas DataFrame as image
Provides:	python-df2img
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-df2img
# df2img: Save a Pandas DataFrame as image

![img](https://img.shields.io/pypi/v/df2img)
![img](https://img.shields.io/pypi/pyversions/df2img)
![img](https://img.shields.io/github/license/andreas-vester/df2img)
![img](https://img.shields.io/github/issues/andreas-vester/df2img)
![img](https://img.shields.io/github/stars/andreas-vester/df2img)

## What is it all about?

Have you ever tried to save a ``pd.DataFrame`` into an image file? This is not a straightforward process at all. Unfortunately, ``pandas`` itself doesn't provide this functionality out of the box.

**df2img** tries to fill the gap. It is a Python library that greatly simplifies the process of saving a ``pd.DataFrame`` into an image file (e.g. ``png`` or ``jpg``).

It is a wrapper/convenience function in order to create a ``plotly`` Table. That is, one can use ``plotly``'s styling function to format the table.


## Dependencies

**df2img** has a limited number of dependencies, namely

- ``pandas``
- ``plotly``
- ``kaleido``


## Documentation

An extensive documentation is available at https://df2img.dev.


## Quickstart

You can install the package via ``pip``.

```bash
pip install df2img
```

Using ``poetry``?

```bash
poetry add df2img
```

Let's create a simple ``pd.DataFrame`` with some dummy data:

```python
import pandas as pd

import df2img

df = pd.DataFrame(
    data=dict(
        float_col=[1.4, float("NaN"), 250, 24.65],
        str_col=("string1", "string2", float("NaN"), "string4"),
    ),
    index=["row1", "row2", "row3", "row4"],
)
```
```python
      float_col  str_col
row1       1.40  string1
row2        NaN  string2
row3     250.00      NaN
row4      24.65  string4
```

### Basics

Saving ``df`` into a png-file now takes just two lines of code including some styling out of the box.

* First, we create a ``plotly`` figure.
* Second, we save the figure to disk.

```python
fig = df2img.plot_dataframe(df, fig_size=(500, 140))

df2img.save_dataframe(fig=fig, filename="plot1.png")
```

![img](https://github.com/andreas-vester/df2img/blob/main/docs/img/plot1.png?raw=true)


### Formatting

You can control the settings for the header row via the ``tbl_header`` input argument. This accepts a regular ``dict``. This ``dict`` can comprise various key/value pairs that are also accepted by ``plotly``. All available key/value pairs can be seen at ``plotly``'s website at https://plotly.com/python/reference/table/#table-header.

Let's set the header row in a different color and size. Also, let's set the alignment to "left".

```python
fig = df2img.plot_dataframe(
    df,
    tbl_header=dict(
        align="left",
        fill_color="blue",
        font_color="white",
        font_size=14,
    ),
    fig_size=(500, 140),
)
```
![img](https://github.com/andreas-vester/df2img/blob/main/docs/img/plot2.png?raw=true)


Controlling the table body (cells) is basically the same. Just use the ``tbl_cells`` input argument, which happens to be a ``dict``, too.
See https://plotly.com/python/reference/table/#table-cells for all the possible key/value pairs.

Let's print the table cell values in yellow on a green background and align them "right".

```python
fig = df2img.plot_dataframe(
    df,
    tbl_cells=dict(
        align="right",
        fill_color="green",
        font_color="yellow",
    ),
    fig_size=(500, 140),
)
```

![img](https://github.com/andreas-vester/df2img/blob/main/docs/img/plot3.png?raw=true)


You can alternate row colors for better readability by using the ``row_fill_color`` input argument. Using HEX colors is also possible:

```python
fig = df2img.plot_dataframe(
    df,
    row_fill_color=("#ffffff", "#d7d8d6"),
    fig_size=(500, 140),
)
```

![img](https://github.com/andreas-vester/df2img/blob/main/docs/img/plot4.png?raw=true)


Setting the title will be controlled via the ``title`` input argument. You can find the relevant key/value pairs here: https://plotly.com/python/reference/layout/#layout-title.

Let's put the title in a different font and size. In addition, we can control the alignment via the ``x`` key/value pair. It sets the x (horizontal) position in normalized coordinates from "0" (left) to "1" (right).

```python
  fig = df2img.plot_dataframe(
      df,
      title=dict(
          font_color="darkred",
          font_family="Times New Roman",
          font_size=24,
          text="This is a title starting at the x-value x=0.1",
          x=0.1,
          xanchor="left",
      ),
      fig_size=(500, 140),
  )
  ```

![img](https://github.com/andreas-vester/df2img/blob/main/docs/img/plot5.png?raw=true)


You can also control relative column width via the ``col_width`` argument. Let's set the first column's width triple the width of the third column and the second column's width double the width of the third column.

```python
fig = df2img.plot_dataframe(
    df,
    col_width=[3, 2, 1],
    fig_size=(500, 140),
)
```

![img](https://github.com/andreas-vester/df2img/blob/main/docs/img/plot6.png?raw=true)

## Contributing to df2img

If you consider to contribute to **df2img**, please read the [Contributing to df2img](./CONTRIBUTING.md) section in the documentation. This document is supposed to guide you through the whole process.


%package help
Summary:	Development documents and examples for df2img
Provides:	python3-df2img-doc
%description help
# df2img: Save a Pandas DataFrame as image

![img](https://img.shields.io/pypi/v/df2img)
![img](https://img.shields.io/pypi/pyversions/df2img)
![img](https://img.shields.io/github/license/andreas-vester/df2img)
![img](https://img.shields.io/github/issues/andreas-vester/df2img)
![img](https://img.shields.io/github/stars/andreas-vester/df2img)

## What is it all about?

Have you ever tried to save a ``pd.DataFrame`` into an image file? This is not a straightforward process at all. Unfortunately, ``pandas`` itself doesn't provide this functionality out of the box.

**df2img** tries to fill the gap. It is a Python library that greatly simplifies the process of saving a ``pd.DataFrame`` into an image file (e.g. ``png`` or ``jpg``).

It is a wrapper/convenience function in order to create a ``plotly`` Table. That is, one can use ``plotly``'s styling function to format the table.


## Dependencies

**df2img** has a limited number of dependencies, namely

- ``pandas``
- ``plotly``
- ``kaleido``


## Documentation

An extensive documentation is available at https://df2img.dev.


## Quickstart

You can install the package via ``pip``.

```bash
pip install df2img
```

Using ``poetry``?

```bash
poetry add df2img
```

Let's create a simple ``pd.DataFrame`` with some dummy data:

```python
import pandas as pd

import df2img

df = pd.DataFrame(
    data=dict(
        float_col=[1.4, float("NaN"), 250, 24.65],
        str_col=("string1", "string2", float("NaN"), "string4"),
    ),
    index=["row1", "row2", "row3", "row4"],
)
```
```python
      float_col  str_col
row1       1.40  string1
row2        NaN  string2
row3     250.00      NaN
row4      24.65  string4
```

### Basics

Saving ``df`` into a png-file now takes just two lines of code including some styling out of the box.

* First, we create a ``plotly`` figure.
* Second, we save the figure to disk.

```python
fig = df2img.plot_dataframe(df, fig_size=(500, 140))

df2img.save_dataframe(fig=fig, filename="plot1.png")
```

![img](https://github.com/andreas-vester/df2img/blob/main/docs/img/plot1.png?raw=true)


### Formatting

You can control the settings for the header row via the ``tbl_header`` input argument. This accepts a regular ``dict``. This ``dict`` can comprise various key/value pairs that are also accepted by ``plotly``. All available key/value pairs can be seen at ``plotly``'s website at https://plotly.com/python/reference/table/#table-header.

Let's set the header row in a different color and size. Also, let's set the alignment to "left".

```python
fig = df2img.plot_dataframe(
    df,
    tbl_header=dict(
        align="left",
        fill_color="blue",
        font_color="white",
        font_size=14,
    ),
    fig_size=(500, 140),
)
```
![img](https://github.com/andreas-vester/df2img/blob/main/docs/img/plot2.png?raw=true)


Controlling the table body (cells) is basically the same. Just use the ``tbl_cells`` input argument, which happens to be a ``dict``, too.
See https://plotly.com/python/reference/table/#table-cells for all the possible key/value pairs.

Let's print the table cell values in yellow on a green background and align them "right".

```python
fig = df2img.plot_dataframe(
    df,
    tbl_cells=dict(
        align="right",
        fill_color="green",
        font_color="yellow",
    ),
    fig_size=(500, 140),
)
```

![img](https://github.com/andreas-vester/df2img/blob/main/docs/img/plot3.png?raw=true)


You can alternate row colors for better readability by using the ``row_fill_color`` input argument. Using HEX colors is also possible:

```python
fig = df2img.plot_dataframe(
    df,
    row_fill_color=("#ffffff", "#d7d8d6"),
    fig_size=(500, 140),
)
```

![img](https://github.com/andreas-vester/df2img/blob/main/docs/img/plot4.png?raw=true)


Setting the title will be controlled via the ``title`` input argument. You can find the relevant key/value pairs here: https://plotly.com/python/reference/layout/#layout-title.

Let's put the title in a different font and size. In addition, we can control the alignment via the ``x`` key/value pair. It sets the x (horizontal) position in normalized coordinates from "0" (left) to "1" (right).

```python
  fig = df2img.plot_dataframe(
      df,
      title=dict(
          font_color="darkred",
          font_family="Times New Roman",
          font_size=24,
          text="This is a title starting at the x-value x=0.1",
          x=0.1,
          xanchor="left",
      ),
      fig_size=(500, 140),
  )
  ```

![img](https://github.com/andreas-vester/df2img/blob/main/docs/img/plot5.png?raw=true)


You can also control relative column width via the ``col_width`` argument. Let's set the first column's width triple the width of the third column and the second column's width double the width of the third column.

```python
fig = df2img.plot_dataframe(
    df,
    col_width=[3, 2, 1],
    fig_size=(500, 140),
)
```

![img](https://github.com/andreas-vester/df2img/blob/main/docs/img/plot6.png?raw=true)

## Contributing to df2img

If you consider to contribute to **df2img**, please read the [Contributing to df2img](./CONTRIBUTING.md) section in the documentation. This document is supposed to guide you through the whole process.


%prep
%autosetup -n df2img-0.2.11

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-df2img -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Tue Jun 20 2023 Python_Bot <Python_Bot@openeuler.org> - 0.2.11-1
- Package Spec generated