Files
.com/tablib.html
Kenneth Reitz 2501bb4223 content update
2011-01-03 00:41:27 -05:00

186 lines
4.5 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<title>Tablib</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="./theme/css/main.css" type="text/css" />
<link href="./feeds/all.atom.xml" type="application/atom+xml" rel="alternate" title="Kenneth's log ATOM Feed" />
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<!--[if lte IE 7]>
<link rel="stylesheet" type="text/css" media="all" href="./css/ie.css"/>
<script src="./js/IE8.js" type="text/javascript"></script><![endif]-->
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" media="all" href="./css/ie6.css"/><![endif]-->
</head>
<body id="index" class="home">
<a href="http://github.com/kennethreitz/">
<img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub" />
</a>
<header id="banner" class="body">
<h1>
<a href=".">Kenneth's log </a>
</h1>
<nav><ul>
<li >
<a href="./category/Life.html">Life</a>
</li>
<li >
<a href="./category/Code.html">Code</a>
</li>
<li class="active">
<a href="./category/projects.html">projects</a>
</li>
</ul></nav>
</header><!-- /#banner -->
<section id="content" class="body">
<article>
<header> <h1 class="entry-title"><a href="tablib.html"
rel="bookmark" title="Permalink to Tablib">Tablib</a></h1> </header>
<p>Tablib is an extensive Python module for working with tabular datasets. It allows you create tables of data using standard Python datatypes, manipulate them, and easily export to Excel, JSON, YAML, and CSV.</p>
<p>Basic Usage:</p>
<pre class="literal-block">
import tablib
headers = ('first_name', 'last_name', 'gpa')
data = [('John', 'Adams', 90), ('George', 'Washington', 67)]
data = tablib.Dataset(*data, headers=headers)
</pre>
<p>You can manipulate your data like a standard Python list:</p>
<pre class="literal-block">
&gt;&gt;&gt; data.append(('Henry', 'Ford', 83))
&gt;&gt;&gt; print data['first_name']
['John', 'George', 'Henry']
&gt;&gt;&gt; del data[1]
</pre>
<p>You can easily export your data to JSON, YAML, XLS, and CSV.</p>
<pre class="literal-block">
&gt;&gt;&gt; print data.json
[{&quot;first_name&quot;: &quot;John&quot;, &quot;last_name&quot;: &quot;Adams&quot;, &quot;gpa&quot;: 90},
{&quot;first_name&quot;: &quot;Henry&quot;, &quot;last_name&quot;: &quot;Ford&quot;, &quot;gpa&quot;: 83}]
&gt;&gt;&gt; print data.yaml
- {age: 90, first_name: John, last_name: Adams}
- {age: 83, first_name: Henry, last_name: Ford}
&gt;&gt;&gt; print data.csv
first_name,last_name,age
John,Adams,90
Henry,Ford,83
&gt;&gt;&gt; open('people.xls', 'w').write(data.xls)
</pre>
<p>Excel files with multiple sheets are also supported (via the DataBook object).</p>
<p>[Source on GitHub] [PyPi Listing]</p>
</div><!-- /.entry-content -->
</article>
</section>
<section id="extras" class="body">
<div class="blogroll">
<h2>Links</h2>
<ul>
<li><a href="http://github.com/kennethreitz">GitHub Repos</a></li>
<li><a href="http://flickr.com/kennethreitz">Photography (Flickr)</a></li>
<li><a href="http://twitter.com/kennethreitz">Latest Tweets</a></li>
<li><a href="http://www.linkedin.com/in/kennethreitz">R&eacute;sum&eacute;</a></li>
<li><a href="http://pick.im/kenneth-reitz">Design Portfolio</a></li>
<li><a href="http://laterstars.com/kennethreitz">Later Stars</a></li>
</ul>
</div><!-- /.blogroll -->
<div class="social">
<ul>
<li><a href="./feeds/all.atom.xml" rel="alternate">atom feed</a></li>
<li><a href="http://facebook.com/kennethreitz">Facebook</a></li>
</ul>
</div><!-- /.social -->
</section><!-- /#extras -->
<footer id="contentinfo" class="body">
<address id="about" class="vcard body">
&copy; 2011 Kenneth Reitz &amp; co. All Rights Reserved.
</address><!-- /#about -->
</footer><!-- /#contentinfo -->
<script type="text/javascript">
var disqus_shortname = 'kennethreitz';
(function () {
var s = document.createElement('script'); s.async = true;
s.type = 'text/javascript';
s.src = 'http://' + disqus_shortname + '.disqus.com/count.js';
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
}());
</script>
<script type="text/javascript" charset="utf-8">
var disqus_developer = 1;
</script>
</body>
</html>