You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Fix for eval_functions=True
* Allow blank characters before "function"
* Add "Loading..." below the table header
* Remove Python 2 specific code
* init_notebook_mode(all_interactive=False) restores the default HTML tables
<aclass="github-button"href="https://github.com/mwouts/itables"data-icon="octicon-star"data-show-count="true"aria-label="Star mwouts/itables on GitHub">Star</a>
11
11
12
-
Turn pandas DataFrames and Series into interactive [datatables](https://datatables.net) in your notebooks with `import itables.interactive`:
12
+
Turn pandas DataFrames and Series into interactive [datatables](https://datatables.net) in your notebooks!
@@ -28,17 +28,16 @@ from itables import init_notebook_mode
28
28
init_notebook_mode(all_interactive=True)
29
29
```
30
30
31
+
Then any dataframe will be displayed as an interactive [datatables](https://datatables.net) table:
32
+
31
33
```python
32
34
import world_bank_data as wb
33
35
34
36
df = wb.get_countries()
35
37
df
36
38
```
37
39
38
-
You don't see any table above? Please either open the [HTML export](https://mwouts.github.io/itables/) of this notebook, or run this README on [Binder](https://mybinder.org/v2/gh/mwouts/itables/main?urlpath=lab/tree/README.md)!
39
-
40
-
41
-
Or display just one series or dataframe as an interactive table with the `show` function.
40
+
If you want to display just one series or dataframe as an interactive table, use `itables.show`:
42
41
43
42
```python
44
43
from itables import show
@@ -47,7 +46,11 @@ x = wb.get_series("SP.POP.TOTL", mrv=1, simplify_index=True)
47
46
show(x)
48
47
```
49
48
50
-
# Supported environments
49
+
(NB: In Jupyter Notebook and Jupyter NBconvert, you need to call `init_notebook_mode()` before using `show`).
50
+
51
+
You don't see any table above? Please either open the [HTML export](https://mwouts.github.io/itables/) of this notebook, or run this README on [Binder](https://mybinder.org/v2/gh/mwouts/itables/main?urlpath=lab/tree/README.md)!
52
+
53
+
## Supported environments
51
54
52
55
`itables` has been tested in the following editors:
53
56
- Jupyter Notebook
@@ -58,8 +61,20 @@ show(x)
58
61
- PyCharm (for Jupyter Notebooks)
59
62
- Nteract
60
63
64
+
## Table not loading?
65
+
66
+
If the table just says "Loading...", then maybe
67
+
- You loaded a notebook that is not trusted (run "Trust Notebook" in View / Activate Command Palette)
68
+
- Or you are offline?
69
+
70
+
At the moment `itables` does not have an [offline mode](https://github.com/mwouts/itables/issues/8). While the table data is embedded in the notebook, the `jquery` and `datatables.net` are loaded from a CDN, see our [require.config](https://github.com/mwouts/itables/blob/main/itables/javascript/load_datatables_connected.js) and our [table template](https://github.com/mwouts/itables/blob/main/itables/datatables_template.html), so an internet connection is required to display the tables.
71
+
61
72
# Advanced usage
62
73
74
+
As `itables` is mostly a wrapper for the Javascript [datatables.net](https://datatables.net/) library, you should be able to find help on the datatables.net [forum](https://datatables.net/forums/) and [examples](https://datatables.net/examples/index) for most formatting issues.
75
+
76
+
Below we give a few examples of how the datatables.net examples can be translated to Python with `itables`.
77
+
63
78
## Row sorting
64
79
65
80
Select the order in which the row are sorted with the [datatables' `order`](https://datatables.net/reference/option/order) argument. By default, the rows are sorted according to the first column (`order = [[0, 'asc']]`).
@@ -137,21 +152,25 @@ with pd.option_context("display.float_format", "${:,.2f}".format):
137
152
show(pd.Series([i * math.pi for i inrange(1, 6)]))
138
153
```
139
154
140
-
## Advanced cell formatting
155
+
## Advanced cell formatting with JS callbacks
156
+
157
+
You can use Javascript callbacks to set the cell or row style depending on the cell content.
141
158
142
-
Datatables allows to set the cell or row style depending on the cell content, with either the [createdRow](https://datatables.net/reference/option/createdRow) or [createdCell](https://datatables.net/reference/option/columns.createdCell) callback. For instance, if we want the cells with negative numbers to be colored in red, we can use the `columnDefs.createdCell` argument as follows:
159
+
The example below, in which we color in red the cells with negative numbers, is directly inspired by the corresponding datatables.net[example](https://datatables.net/reference/option/columns.createdCell).
0 commit comments