Skip to content

Commit 6f484a7

Browse files
committed
DOC: Move qt interface instructions to faq.rst from visualization.rst
1 parent 54fbeaf commit 6f484a7

File tree

2 files changed

+75
-76
lines changed

2 files changed

+75
-76
lines changed

doc/source/faq.rst

+75
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,78 @@ using something similar to the following:
266266
See `the NumPy documentation on byte order
267267
<http://docs.scipy.org/doc/numpy/user/basics.byteswapping.html>`__ for more
268268
details.
269+
270+
271+
Visualizing Data in Qt applications
272+
-----------------------------------
273+
274+
There is experimental support for visualizing DataFrames in PyQt4 and PySide
275+
applications. At the moment you can display and edit the values of the cells
276+
in the DataFrame. Qt will take care of displaying just the portion of the
277+
DataFrame that is currently visible and the edits will be immediately saved to
278+
the underlying DataFrame
279+
280+
To demonstrate this we will create a simple PySide application that will switch
281+
between two editable DataFrames. For this will use the ``DataFrameModel`` class
282+
that handles the access to the DataFrame, and the ``DataFrameWidget``, which is
283+
just a thin layer around the ``QTableView``.
284+
285+
.. code-block:: python
286+
287+
import numpy as np
288+
import pandas as pd
289+
from pandas.sandbox.qtpandas import DataFrameModel, DataFrameWidget
290+
from PySide import QtGui, QtCore
291+
292+
# Or if you use PyQt4:
293+
# from PyQt4 import QtGui, QtCore
294+
295+
class MainWidget(QtGui.QWidget):
296+
def __init__(self, parent=None):
297+
super(MainWidget, self).__init__(parent)
298+
299+
# Create two DataFrames
300+
self.df1 = pd.DataFrame(np.arange(9).reshape(3, 3),
301+
columns=['foo', 'bar', 'baz'])
302+
self.df2 = pd.DataFrame({
303+
'int': [1, 2, 3],
304+
'float': [1.5, 2.5, 3.5],
305+
'string': ['a', 'b', 'c'],
306+
'nan': [np.nan, np.nan, np.nan]
307+
}, index=['AAA', 'BBB', 'CCC'],
308+
columns=['int', 'float', 'string', 'nan'])
309+
310+
# Create the widget and set the first DataFrame
311+
self.widget = DataFrameWidget(self.df1)
312+
313+
# Create the buttons for changing DataFrames
314+
self.button_first = QtGui.QPushButton('First')
315+
self.button_first.clicked.connect(self.on_first_click)
316+
self.button_second = QtGui.QPushButton('Second')
317+
self.button_second.clicked.connect(self.on_second_click)
318+
319+
# Set the layout
320+
vbox = QtGui.QVBoxLayout()
321+
vbox.addWidget(self.widget)
322+
hbox = QtGui.QHBoxLayout()
323+
hbox.addWidget(self.button_first)
324+
hbox.addWidget(self.button_second)
325+
vbox.addLayout(hbox)
326+
self.setLayout(vbox)
327+
328+
def on_first_click(self):
329+
'''Sets the first DataFrame'''
330+
self.widget.setDataFrame(self.df1)
331+
332+
def on_second_click(self):
333+
'''Sets the second DataFrame'''
334+
self.widget.setDataFrame(self.df2)
335+
336+
if __name__ == '__main__':
337+
import sys
338+
339+
# Initialize the application
340+
app = QtGui.QApplication(sys.argv)
341+
mw = MainWidget()
342+
mw.show()
343+
app.exec_()

doc/source/visualization.rst

-76
Original file line numberDiff line numberDiff line change
@@ -594,79 +594,3 @@ Andrews curves charts:
594594
595595
@savefig andrews_curve_winter.png
596596
andrews_curves(data, 'Name', colormap='winter')
597-
598-
599-
****************************************
600-
Visualizing your data in Qt applications
601-
****************************************
602-
603-
There is an experimental support for visualizing DataFrames in PyQt4 and PySide
604-
applications. At the moment you can display and edit the values of the cells
605-
in the DataFrame. Qt will take care of displaying just the portion of the
606-
DataFrame that is currently visible and the edits will be immediately saved to
607-
the underlying DataFrame
608-
609-
To demonstrate this we will create a simple PySide application that will switch
610-
between two editable DataFrames. For this will use the ``DataFrameModel`` class
611-
that handles the access to the DataFrame, and the ``DataFrameWidget``, which is
612-
just a thin layer around the ``QTableView``.
613-
614-
.. code-block:: python
615-
616-
import numpy as np
617-
import pandas as pd
618-
from pandas.sandbox.qtpandas import DataFrameModel, DataFrameWidget
619-
from PySide import QtGui, QtCore
620-
621-
# Or if you use PyQt4:
622-
# from PyQt4 import QtGui, QtCore
623-
624-
class MainWidget(QtGui.QWidget):
625-
def __init__(self, parent=None):
626-
super(MainWidget, self).__init__(parent)
627-
628-
# Create two DataFrames
629-
self.df1 = pd.DataFrame(np.arange(9).reshape(3, 3),
630-
columns=['foo', 'bar', 'baz'])
631-
self.df2 = pd.DataFrame({
632-
'int': [1, 2, 3],
633-
'float': [1.5, 2.5, 3.5],
634-
'string': ['a', 'b', 'c'],
635-
'nan': [np.nan, np.nan, np.nan]
636-
}, index=['AAA', 'BBB', 'CCC'],
637-
columns=['int', 'float', 'string', 'nan'])
638-
639-
# Create the widget and set the first DataFrame
640-
self.widget = DataFrameWidget(self.df1)
641-
642-
# Create the buttons for changing DataFrames
643-
self.button_first = QtGui.QPushButton('First')
644-
self.button_first.clicked.connect(self.on_first_click)
645-
self.button_second = QtGui.QPushButton('Second')
646-
self.button_second.clicked.connect(self.on_second_click)
647-
648-
# Set the layout
649-
vbox = QtGui.QVBoxLayout()
650-
vbox.addWidget(self.widget)
651-
hbox = QtGui.QHBoxLayout()
652-
hbox.addWidget(self.button_first)
653-
hbox.addWidget(self.button_second)
654-
vbox.addLayout(hbox)
655-
self.setLayout(vbox)
656-
657-
def on_first_click(self):
658-
'''Sets the first DataFrame'''
659-
self.widget.setDataFrame(self.df1)
660-
661-
def on_second_click(self):
662-
'''Sets the second DataFrame'''
663-
self.widget.setDataFrame(self.df2)
664-
665-
if __name__ == '__main__':
666-
import sys
667-
668-
# Initialize the application
669-
app = QtGui.QApplication(sys.argv)
670-
mw = MainWidget()
671-
mw.show()
672-
app.exec_()

0 commit comments

Comments
 (0)