Skip to content

Commit

Permalink
initial code commit
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmjk committed Sep 8, 2018
1 parent 7924935 commit 14ad5d7
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

# pandas-qgrid-mixin

pandas/ipython mix-in to use Qgrid as default DataFrame display method

## What it does?

Injects `_ipython_display_` method into `pandas.DataFrame` that instead of the usual HTML table representation shows a `QgridWidget`.

## Install

```sh
pip3 install git+git://github.com/0xmjk/pandas-qgrid-mixin
```

## Example

```python
import pandas as pd
import pandas_qgrid_mixin

pd.DataFrame([{"A": 5, "B": 6}, {"A": 10, "B": 12}])
```

![png](screenshot.png)

## Options

Additional `pandas.display` options:

| Option | Type | Default | Description |
| --- | --- | --- | --- |
| pandas.display.use_qgrid_doc | bool | True | Display DataFrames using QgridWidget instead of default HTML. |
| pandas.display.show_qgrid_options_doc | dict | {}| Kwargs for grid.show_grid() |

## Links

* [Qgrid](https://github.com/quantopian/qgrid) is an interactive grid for sorting, filtering, and editing DataFrames in Jupyter notebooks
30 changes: 30 additions & 0 deletions pandas_qgrid_mixin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from IPython.display import display, HTML
import qgrid
import pandas as pd

def DataFrame_ipython_display_(self):
use_qgrid = False
show_qgrid_options = {}
try:
use_qgrid = pd.options.display.use_qgrid
show_qgrid_options = pd.options.display.show_qgrid_options.d
except Exception:
pass

if use_qgrid:
widget = qgrid.show_grid(self, **show_qgrid_options)
return widget._ipython_display_()
else:
return display(HTML(self._repr_html_()))

pd.DataFrame._ipython_display_ = DataFrame_ipython_display_
use_qgrid_doc = """
: bool
Display DataFrames using QgridWidget instead of default HTML.
"""
show_qgrid_options_doc = """
: dict
Kwargs for qgrid.show_grid()
"""
pd.core.config.register_option("display.use_qgrid", True, doc=use_qgrid_doc)
pd.core.config.register_option("display.show_qgrid_options", {}, doc=show_qgrid_options_doc)
Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from setuptools import setup

setup(
name='pandas-qgrid-mixin',
install_requires=['pandas', 'qgrid', 'ipython>=4.0.0'],
version='0.1',
description='pandas/ipython mix-in to use qgrid as default DataFrame display method',
url='http://github.com/0xmjk/pandas-qgrid-mixin',
license='Apache-2.0',
packages=['pandas_qgrid_mixin'],
zip_safe=False)

0 comments on commit 14ad5d7

Please sign in to comment.