Most viewed recipes tagged "data"http://code.activestate.com/recipes/tags/data/views/2016-12-17T19:08:33-08:00ActiveState Code RecipesValidate data easily with JSON Schema (Python)
2015-12-06T21:23:48-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579135-validate-data-easily-with-json-schema/
<p style="color: grey">
Python
recipe 579135
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/json/">json</a>, <a href="/recipes/tags/jsonschema/">jsonschema</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python2/">python2</a>).
</p>
<p>This recipe shows how to use the jsonschema Python library, which implements the JSON Schema specification, to easily validate your Python data. It sends good output to stdout and bad output to stderr, for demo purposes.</p>
<p>jsonschema Python library: <a href="https://pypi.python.org/pypi/jsonschema" rel="nofollow">https://pypi.python.org/pypi/jsonschema</a></p>
<p>JSON Schema: <a href="http://json-schema.org/" rel="nofollow">http://json-schema.org/</a></p>
Populate SQL tables from CSV data files (Python)
2011-02-02T21:21:49-08:00James Millshttp://code.activestate.com/recipes/users/4167757/http://code.activestate.com/recipes/577559-populate-sql-tables-from-csv-data-files/
<p style="color: grey">
Python
recipe 577559
by <a href="/recipes/users/4167757/">James Mills</a>
(<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/sql/">sql</a>).
</p>
<p>Just a quick recipe I developed a few years ago that I thought
might be useful to others. Basically it takes as input a
data file with comma separated values (CSV) and translates
this into a series of SQL "INSERT" statements allowing you
to then feed this into MySQL, SQLite, or any other database.</p>
<p>Example Usage:</p>
<p>$ cat cars.csv
Year,Make,Model,Length
1997,Ford,E350,2.34
2000,Mercury,Cougar,2.38</p>
<p>$ sqlite3 cars.db "CREATE TABLE cars (Year, Make, Model, Length)"</p>
<p>$ ./csv2sql.py cars.csv | sqlite3 cars.db </p>
<p>$ sqlite3 cars.db "SELECT * FROM cars"
1997|Ford|E350|2.34
2000|Mercury|Cougar|2.38</p>
<p>Enjoy! Feedback welcome!</p>
<p>cheers
James Mills / prologic</p>
2-3 Tree (Python)
2011-10-08T21:46:03-07:00Borishttp://code.activestate.com/recipes/users/4179529/http://code.activestate.com/recipes/577898-2-3-tree/
<p style="color: grey">
Python
recipe 577898
by <a href="/recipes/users/4179529/">Boris</a>
(<a href="/recipes/tags/2_3tree/">2_3tree</a>, <a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/structure/">structure</a>, <a href="/recipes/tags/tree/">tree</a>).
</p>
<p>My implementation of 2-3 Trees on python</p>
Read CSV with D and write it to PDF with Python (Python)
2016-10-26T17:49:00-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580710-read-csv-with-d-and-write-it-to-pdf-with-python/
<p style="color: grey">
Python
recipe 580710
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/formats/">formats</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdf_generation/">pdf_generation</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows how to read data from a CSV file with a D program and write that data to a PDF file with a Python program - all in a single command-line invocation (after writing the individual programs, of course).</p>
<p>It requires the xtopdf toolkit, which you can get from:</p>
<p><a href="https://bitbucket.org/vasudevram/xtopdf" rel="nofollow">https://bitbucket.org/vasudevram/xtopdf</a></p>
<p>Instructions for installing xtopdf:</p>
<p><a href="http://jugad2.blogspot.in/2012/07/guide-to-installing-and-using-xtopdf.html" rel="nofollow">http://jugad2.blogspot.in/2012/07/guide-to-installing-and-using-xtopdf.html</a></p>
<p>xtopdf in turn requires the open source version of the ReportLab toolkit, which you can get from:</p>
<p><a href="http://www.reportlab.com/ftp" rel="nofollow">http://www.reportlab.com/ftp</a> (<a href="http://www.reportlab.com/ftp/reportlab-1.21.1.tar.gz%29" rel="nofollow">http://www.reportlab.com/ftp/reportlab-1.21.1.tar.gz)</a></p>
<p>It also requires the DMD compiler to compile the D program - this was the version used:</p>
<p>DMD32 D Compiler v2.071.2</p>
Use PrettyTable and xtopdf to create PDF tables with borders, alignment and padding (Python)
2015-01-24T21:21:27-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579012-use-prettytable-and-xtopdf-to-create-pdf-tables-wi/
<p style="color: grey">
Python
recipe 579012
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/prettytable/">prettytable</a>, <a href="/recipes/tags/string/">string</a>, <a href="/recipes/tags/tabular/">tabular</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows how to create tabular data in PDF format, supporting neat borders, and alignment and padding of columns, using the Python libraries called PrettyTable and xtopdf.</p>
Filtering CSV data by fields (cut for csv) (Python)
2011-02-02T21:39:45-08:00James Millshttp://code.activestate.com/recipes/users/4167757/http://code.activestate.com/recipes/577560-filtering-csv-data-by-fields-cut-for-csv/
<p style="color: grey">
Python
recipe 577560
by <a href="/recipes/users/4167757/">James Mills</a>
(<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/cut/">cut</a>, <a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/filter/">filter</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>Ever wanted to take a CSV file as input, cut it up
and only extract the fields that you want ?</p>
<p>Here's how!</p>
<p>$ cat cars.csv
Year,Make,Model,Length
1997,Ford,E350,2.34
2000,Mercury,Cougar,2.38</p>
<p>$ csvcut.py -f 0 -f -1 - < cars.csv
Year,Length
1997,2.34
2000,2.38</p>
<p>--JamesMills (prologic)</p>
Finding the sizes of various Python data types (Python)
2016-04-28T18:28:59-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580655-finding-the-sizes-of-various-python-data-types/
<p style="color: grey">
Python
recipe 580655
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/datastructures/">datastructures</a>, <a href="/recipes/tags/memory/">memory</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python2/">python2</a>, <a href="/recipes/tags/system/">system</a>, <a href="/recipes/tags/type/">type</a>).
</p>
<p>This recipe shows how to find the sizes of various common data types in Python, both built-in and user-defined. It uses the sys.getsizeof() function and also discusses a few other points of interest.</p>
Creating fake data using numpy (Python)
2009-08-07T09:22:34-07:00tat.wrighthttp://code.activestate.com/recipes/users/4171357/http://code.activestate.com/recipes/576870-creating-fake-data-using-numpy/
<p style="color: grey">
Python
recipe 576870
by <a href="/recipes/users/4171357/">tat.wright</a>
(<a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/fake/">fake</a>, <a href="/recipes/tags/gaussian/">gaussian</a>, <a href="/recipes/tags/graph/">graph</a>, <a href="/recipes/tags/histogram/">histogram</a>, <a href="/recipes/tags/normal/">normal</a>, <a href="/recipes/tags/sample_data/">sample_data</a>).
</p>
<p>Create a deliberately bad normal distribution for sample data - varying the badness, mean, standard deviation and range of results shown.</p>
[xtopdf] Publish Delimiter-Separated Values (DSV data) to PDF (Python)
2016-12-17T19:08:33-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580736-xtopdf-publish-delimiter-separated-values-dsv-data/
<p style="color: grey">
Python
recipe 580736
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/formats/">formats</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdf_generation/">pdf_generation</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/tsv/">tsv</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>).
</p>
<p>This recipe shows how to publish delimiter-separated values (a commonly used tabular data format) to PDF, using the xtopdf toolkit for PDF creation. It lets the user specify the delimiter via one of two command-line options - an ASCII code or an ASCII character. As Unix filters tend to do, it can operate either on standard input or on input filenames given as command-line arguments. In the case of multiple inputs via files, each input goes to a separate PDF output file.</p>
Process Delimiter-Separated Values data with Python (Python)
2016-11-24T23:57:35-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580722-process-delimiter-separated-values-data-with-pytho/
<p style="color: grey">
Python
recipe 580722
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/dsv/">dsv</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/utility/">utility</a>).
</p>
<p>This recipe shows how to read and process delimiter-separated values (DSV) data with a Python command-line program. It provides two ways of specifying the delimiter character, by an ASCII character or an ASCII code, which makes it more flexible than allowing only a character. It allows the DSV data to be specified as one or more filenames on the command line, or given via the standard input of the program.</p>
data_dump.py, like the Unix od (octal dump) command (Python)
2015-11-01T12:43:38-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579120-data_dumppy-like-the-unix-od-octal-dump-command/
<p style="color: grey">
Python
recipe 579120
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/dump/">dump</a>, <a href="/recipes/tags/hexadecimal/">hexadecimal</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/octal/">octal</a>, <a href="/recipes/tags/od/">od</a>, <a href="/recipes/tags/representation/">representation</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utility/">utility</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>This recipe implements a simple data dump tool, roughly like the od command of Unix, which stands for octal dump (though od can also dump data in hex and other formats). This tool dumps data in character and hex formats, in this version. This is data_dump.py version 1.</p>
Retrieving the median of a set in constant time (Python)
2011-04-19T15:00:57-07:00jimmy2timeshttp://code.activestate.com/recipes/users/4177690/http://code.activestate.com/recipes/577661-retrieving-the-median-of-a-set-in-constant-time/
<p style="color: grey">
Python
recipe 577661
by <a href="/recipes/users/4177690/">jimmy2times</a>
(<a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/heap/">heap</a>, <a href="/recipes/tags/median/">median</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/retrieving/">retrieving</a>, <a href="/recipes/tags/structure/">structure</a>).
Revision 2.
</p>
<p>Provides a data structure for a queue of integers whose get() method returns the median element. The interface is similar to the standard Queue module, with an added method top() to retrieve the median without removing it.</p>
Data (A Class For Arbitrary Data) (Python)
2015-08-03T15:22:40-07:00Alfehttp://code.activestate.com/recipes/users/4182236/http://code.activestate.com/recipes/579092-data-a-class-for-arbitrary-data/
<p style="color: grey">
Python
recipe 579092
by <a href="/recipes/users/4182236/">Alfe</a>
(<a href="/recipes/tags/class/">class</a>, <a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/lightweight/">lightweight</a>).
</p>
<p>A class which is designed to be easy to use when one needs a piece of data with a minimum of source required.</p>
<p>Usage:</p>
<pre class="prettyprint"><code>shop = Data(owner="Homer", address="down the street", ice=Data(flavor="vanilla", amount=3))
print shop
Data:
owner = 'Homer'
ice = Data:
amount = 3
flavor = 'vanilla'
address = 'down the street'
</code></pre>
Kids Level Analogue Data Logger, (Transient Recorder), Program. (Python)
2011-07-31T16:14:48-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/577796-kids-level-analogue-data-logger-transient-recorder/
<p style="color: grey">
Python
recipe 577796
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/amiga/">amiga</a>, <a href="/recipes/tags/analogue/">analogue</a>, <a href="/recipes/tags/anim/">anim</a>, <a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/arduino/">arduino</a>, <a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/demo/">demo</a>, <a href="/recipes/tags/display/">display</a>, <a href="/recipes/tags/e_uae/">e_uae</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/logger/">logger</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/program/">program</a>, <a href="/recipes/tags/windows/">windows</a>, <a href="/recipes/tags/winuae/">winuae</a>).
Revision 2.
</p>
<p>This code is kids level Analogue Data-Logger(/Transient-Recorder), using the Arduino series of dev' boards.</p>
<p>It is no where near completion and is a second feeder/feeler upload only.</p>
<p>It is designed to work from Classic Text Mode Python from Versions 1.4.0 to 2.7.2 on a Classic AMIGA, WinUAE, Linux and Windows, (32 bit), to Vista.
Not tested on Python for Windows 7, (32 bit), nor Mac OSX flavours as I don't have these OSes.</p>
<p>Linux versions run from a default root terminal for the time being.</p>
<p>The Arduino dev' board IS catered for in the code for the above platforms just thoroughly read the code for more information. It defaults to a DEMO mode so you can see it working...</p>
<p>The test code for the Arduino Diecimila Dev Board is here:-</p>
<p><a href="http://code.activestate.com/recipes/577625-arduino-diecimila-board-access-inside-winuae-demo/" rel="nofollow">http://code.activestate.com/recipes/577625-arduino-diecimila-board-access-inside-winuae-demo/</a></p>
<p>Enjoy finding simple solutions to often very difficult problems... ;o)</p>
<p>Bazza, G0LCU...</p>
RFC 822-style parser (Python)
2010-01-09T22:46:42-08:00Karl Dickmanhttp://code.activestate.com/recipes/users/4172760/http://code.activestate.com/recipes/576996-rfc-822-style-parser/
<p style="color: grey">
Python
recipe 576996
by <a href="/recipes/users/4172760/">Karl Dickman</a>
(<a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/formats/">formats</a>).
Revision 7.
</p>
<p>In <em>The Art of Unix Programming</em>, Eric S. Raymond describes a data file metaformat based on RFC 822. [http://www.faqs.org/docs/artu/ch05s02.html#id2902039] This is a simple parser for that format.</p>
Extract data from feedjit (Python)
2011-05-03T19:50:27-07:00jrovegnohttp://code.activestate.com/recipes/users/4170207/http://code.activestate.com/recipes/577683-extract-data-from-feedjit/
<p style="color: grey">
Python
recipe 577683
by <a href="/recipes/users/4170207/">jrovegno</a>
(<a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/feedjit/">feedjit</a>).
Revision 2.
</p>
<p>Script to extract data from my live traffic feed from feedjit</p>
Representing a set in a compact way (Python)
2011-04-24T10:55:45-07:00jimmy2timeshttp://code.activestate.com/recipes/users/4177690/http://code.activestate.com/recipes/577660-representing-a-set-in-a-compact-way/
<p style="color: grey">
Python
recipe 577660
by <a href="/recipes/users/4177690/">jimmy2times</a>
(<a href="/recipes/tags/compact/">compact</a>, <a href="/recipes/tags/compressed/">compressed</a>, <a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/set/">set</a>, <a href="/recipes/tags/structure/">structure</a>).
Revision 5.
</p>
<p>Implements a data structure for sets of natural numbers, represented by a single integer. The interface is similar to the built-in structure 'set'.</p>