summaryrefslogtreecommitdiff
path: root/docs/tutorial.rst
diff options
context:
space:
mode:
authorBruno Alla <alla.brunoo@gmail.com>2019-03-02 10:34:19 -0300
committerBruno Alla <alla.brunoo@gmail.com>2019-03-02 10:41:07 -0300
commitf757ab84d1436dff2c32b56fd2d4bbd08968f0c4 (patch)
treee5e81f6a378ed15cc004756f28412c97e067ec9c /docs/tutorial.rst
parent80e72cfa27264efb9f525bd92ce6476c5eadb3e9 (diff)
parentdc24fda41505d9961cd43939893a1cea3598ad18 (diff)
downloadtablib-f757ab84d1436dff2c32b56fd2d4bbd08968f0c4.tar.gz
Merge branch 'master' into bugfix/invalid-ascii-csv
# Conflicts: # setup.py # tablib/compat.py # test_tablib.py
Diffstat (limited to 'docs/tutorial.rst')
-rw-r--r--docs/tutorial.rst30
1 files changed, 23 insertions, 7 deletions
diff --git a/docs/tutorial.rst b/docs/tutorial.rst
index d552e21..1fe11ee 100644
--- a/docs/tutorial.rst
+++ b/docs/tutorial.rst
@@ -115,30 +115,38 @@ Tablib's killer feature is the ability to export your :class:`Dataset` objects i
**Comma-Separated Values** ::
- >>> data.csv
+ >>> data.export('csv')
Last Name,First Name,Age
Reitz,Kenneth,22
Monke,Bessie,20
**JavaScript Object Notation** ::
- >>> data.json
+ >>> data.export('json')
[{"Last Name": "Reitz", "First Name": "Kenneth", "Age": 22}, {"Last Name": "Monke", "First Name": "Bessie", "Age": 20}]
**YAML Ain't Markup Language** ::
- >>> data.yaml
+ >>> data.export('yaml')
- {Age: 22, First Name: Kenneth, Last Name: Reitz}
- {Age: 20, First Name: Bessie, Last Name: Monke}
**Microsoft Excel** ::
- >>> data.xls
+ >>> data.export('xls')
<censored binary data>
+**Pandas DataFrame** ::
+
+ >>> data.export('df')
+ First Name Last Name Age
+ 0 Kenneth Reitz 22
+ 1 Bessie Monke 21
+
+
------------------------
Selecting Rows & Columns
------------------------
@@ -216,7 +224,7 @@ Let's add a dynamic column to our :class:`Dataset` object. In this example, we h
Let's have a look at our data. ::
- >>> data.yaml
+ >>> data.export('yaml')
- {Age: 22, First Name: Kenneth, Grade: 0.6, Last Name: Reitz}
- {Age: 20, First Name: Bessie, Grade: 0.75, Last Name: Monke}
@@ -246,7 +254,7 @@ For example, we can use the data available in the row to guess the gender of a s
Adding this function to our dataset as a dynamic column would result in: ::
- >>> data.yaml
+ >>> data.export('yaml')
- {Age: 22, First Name: Kenneth, Gender: Male, Last Name: Reitz}
- {Age: 20, First Name: Bessie, Gender: Female, Last Name: Monke}
@@ -281,6 +289,14 @@ Now that we have extra meta-data on our rows, we can easily filter our :class:`D
It's that simple. The original :class:`Dataset` is untouched.
+Open an Excel Workbook and read first sheet
+--------------------------------
+
+To open an Excel 2007 and later workbook with a single sheet (or a workbook with multiple sheets but you just want the first sheet), use the following:
+
+data = tablib.Dataset()
+data.xlsx = open('my_excel_file.xlsx', 'rb').read()
+print(data)
Excel Workbook With Multiple Sheets
------------------------------------
@@ -346,7 +362,7 @@ When, it's often useful to create a blank row containing information on the upco
# Write spreadsheet to disk
with open('grades.xls', 'wb') as f:
- f.write(tests.xls)
+ f.write(tests.export('xls'))
The resulting **tests.xls** will have the following layout: