mirror of
https://github.com/kennethreitz/tablib.git
synced 2026-06-05 23:10:17 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bb0abc863e | |||
| 58f6eefe01 | |||
| e4726cb85c | |||
| 412e690289 | |||
| 44e797d70e | |||
| 34c14aca18 | |||
| 7c318adde4 | |||
| 5dd74c0104 | |||
| a50ff92ff2 | |||
| 383d4b9c4e | |||
| 00e2ffa2ef |
@@ -1,6 +1,5 @@
|
||||
language: python
|
||||
python:
|
||||
- 2.6
|
||||
- 2.7
|
||||
- 3.3
|
||||
- 3.4
|
||||
|
||||
+15
-5
@@ -21,6 +21,7 @@ Output formats supported:
|
||||
- Excel (Sets + Books)
|
||||
- JSON (Sets + Books)
|
||||
- YAML (Sets + Books)
|
||||
- Pandas DataFrames (Sets)
|
||||
- HTML (Sets)
|
||||
- TSV (Sets)
|
||||
- OSD (Sets)
|
||||
@@ -64,13 +65,13 @@ Intelligently add new columns: ::
|
||||
|
||||
Slice rows: ::
|
||||
|
||||
>>> print data[:2]
|
||||
>>> print(data[:2])
|
||||
[('John', 'Adams', 90), ('George', 'Washington', 67)]
|
||||
|
||||
|
||||
Slice columns by header: ::
|
||||
|
||||
>>> print data['first_name']
|
||||
>>> print(data['first_name'])
|
||||
['John', 'George', 'Henry']
|
||||
|
||||
Easily delete rows: ::
|
||||
@@ -86,7 +87,7 @@ JSON!
|
||||
+++++
|
||||
::
|
||||
|
||||
>>> print data.json
|
||||
>>> print(data.json)
|
||||
[
|
||||
{
|
||||
"last_name": "Adams",
|
||||
@@ -105,7 +106,7 @@ YAML!
|
||||
+++++
|
||||
::
|
||||
|
||||
>>> print data.yaml
|
||||
>>> print(data.yaml)
|
||||
- {age: 90, first_name: John, last_name: Adams}
|
||||
- {age: 83, first_name: Henry, last_name: Ford}
|
||||
|
||||
@@ -113,7 +114,7 @@ CSV...
|
||||
++++++
|
||||
::
|
||||
|
||||
>>> print data.csv
|
||||
>>> print(data.csv)
|
||||
first_name,last_name,age
|
||||
John,Adams,90
|
||||
Henry,Ford,83
|
||||
@@ -131,6 +132,15 @@ DBF!
|
||||
|
||||
>>> with open('people.dbf', 'wb') as f:
|
||||
... f.write(data.dbf)
|
||||
|
||||
Pandas DataFrame!
|
||||
+++++++++++++++++
|
||||
::
|
||||
|
||||
>>> print(data.df):
|
||||
first_name last_name age
|
||||
0 John Adams 90
|
||||
1 Henry Ford 83
|
||||
|
||||
It's that easy.
|
||||
|
||||
|
||||
+8
-3
@@ -29,18 +29,23 @@ Tablib is an :ref:`MIT Licensed <mit>` format-agnostic tabular dataset library,
|
||||
>>> data = tablib.Dataset(headers=['First Name', 'Last Name', 'Age'])
|
||||
>>> for i in [('Kenneth', 'Reitz', 22), ('Bessie', 'Monke', 21)]:
|
||||
... data.append(i)
|
||||
|
||||
|
||||
>>> print data.json
|
||||
|
||||
>>> print(data.json)
|
||||
[{"Last Name": "Reitz", "First Name": "Kenneth", "Age": 22}, {"Last Name": "Monke", "First Name": "Bessie", "Age": 21}]
|
||||
|
||||
>>> print data.yaml
|
||||
>>> print(data.yaml)
|
||||
- {Age: 22, First Name: Kenneth, Last Name: Reitz}
|
||||
- {Age: 21, First Name: Bessie, Last Name: Monke}
|
||||
|
||||
>>> data.xlsx
|
||||
<censored binary data>
|
||||
|
||||
>>> data.df
|
||||
First Name Last Name Age
|
||||
0 Kenneth Reitz 22
|
||||
1 Bessie Monke 21
|
||||
|
||||
|
||||
Testimonials
|
||||
------------
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
certifi==2017.7.27.1
|
||||
chardet==3.0.4
|
||||
et-xmlfile==1.0.1
|
||||
idna==2.6
|
||||
jdcal==1.3
|
||||
numpy==1.13.1
|
||||
odfpy==1.3.5
|
||||
openpyxl==2.4.8
|
||||
pandas==0.20.3
|
||||
pkginfo==1.4.1
|
||||
python-dateutil==2.6.1
|
||||
pytz==2017.2
|
||||
PyYAML==3.12
|
||||
requests==2.18.4
|
||||
requests-toolbelt==0.8.0
|
||||
six==1.10.0
|
||||
tqdm==4.15.0
|
||||
unicodecsv==0.14.1
|
||||
urllib3==1.22
|
||||
xlrd==1.1.0
|
||||
xlwt==1.3.0
|
||||
@@ -48,8 +48,10 @@ install = [
|
||||
'xlrd',
|
||||
'xlwt',
|
||||
'pyyaml',
|
||||
'pandas'
|
||||
]
|
||||
|
||||
|
||||
with open('tablib/core.py', 'r') as fd:
|
||||
version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
|
||||
fd.read(), re.MULTILINE).group(1)
|
||||
@@ -71,7 +73,6 @@ setup(
|
||||
'Natural Language :: English',
|
||||
'License :: OSI Approved :: MIT License',
|
||||
'Programming Language :: Python',
|
||||
'Programming Language :: Python :: 2.6',
|
||||
'Programming Language :: Python :: 2.7',
|
||||
'Programming Language :: Python :: 3.3',
|
||||
'Programming Language :: Python :: 3.4',
|
||||
|
||||
+14
-2
@@ -18,8 +18,8 @@ from tablib.compat import OrderedDict, unicode
|
||||
|
||||
|
||||
__title__ = 'tablib'
|
||||
__version__ = '0.11.5'
|
||||
__build__ = 0x001104
|
||||
__version__ = '0.12.0'
|
||||
__build__ = 0x001200
|
||||
__author__ = 'Kenneth Reitz'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright 2017 Kenneth Reitz'
|
||||
@@ -570,6 +570,18 @@ class Dataset(object):
|
||||
"""
|
||||
pass
|
||||
|
||||
@property
|
||||
def df():
|
||||
"""A DataFrame representation of the :class:`Dataset` object.
|
||||
|
||||
A dataset object can also be imported by setting the :class:`Dataset.df` attribute: ::
|
||||
|
||||
data = tablib.Dataset()
|
||||
data.df = DataFrame(np.random.randn(6,4))
|
||||
|
||||
Import assumes (for now) that headers exist.
|
||||
"""
|
||||
pass
|
||||
|
||||
@property
|
||||
def json():
|
||||
|
||||
@@ -13,5 +13,6 @@ from . import _xlsx as xlsx
|
||||
from . import _ods as ods
|
||||
from . import _dbf as dbf
|
||||
from . import _latex as latex
|
||||
from . import _df as df
|
||||
|
||||
available = (json, xls, yaml, csv, dbf, tsv, html, latex, xlsx, ods)
|
||||
available = (json, xls, yaml, csv, dbf, tsv, html, latex, xlsx, ods, df)
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
""" Tablib - DataFrame Support.
|
||||
"""
|
||||
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
if sys.version_info[0] > 2:
|
||||
from io import BytesIO
|
||||
else:
|
||||
from cStringIO import StringIO as BytesIO
|
||||
|
||||
from pandas import DataFrame
|
||||
|
||||
import tablib
|
||||
|
||||
from tablib.compat import unicode
|
||||
|
||||
title = 'df'
|
||||
extensions = ('df', )
|
||||
|
||||
def detect(stream):
|
||||
"""Returns True if given stream is a DataFrame."""
|
||||
try:
|
||||
DataFrame(stream)
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
|
||||
def export_set(dset, index=None):
|
||||
"""Returns DataFrame representation of DataBook."""
|
||||
dataframe = DataFrame(dset.dict, columns=dset.headers)
|
||||
return dataframe
|
||||
|
||||
|
||||
def import_set(dset, in_stream):
|
||||
"""Returns dataset from DataFrame."""
|
||||
dset.wipe()
|
||||
dset.dict = in_stream.to_dict(orient='records')
|
||||
+1
-1
@@ -5,7 +5,6 @@
|
||||
import json
|
||||
import unittest
|
||||
import sys
|
||||
import os
|
||||
|
||||
import datetime
|
||||
|
||||
@@ -383,6 +382,7 @@ class TablibTestCase(unittest.TestCase):
|
||||
data.ods
|
||||
data.html
|
||||
data.latex
|
||||
data.df
|
||||
|
||||
def test_datetime_append(self):
|
||||
"""Passes in a single datetime and a single date and exports."""
|
||||
|
||||
Reference in New Issue
Block a user