Popular Python recipes tagged "meta:requires=csv"http://code.activestate.com/recipes/langs/python/tags/meta:requires=csv/2012-12-17T16:16:04-08:00ActiveState Code RecipesConvert CSV to XML (Python)
2010-10-11T06:20:19-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577423-convert-csv-to-xml/
<p style="color: grey">
Python
recipe 577423
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/xml/">xml</a>).
</p>
<p>Convert CSV to XML.</p>
Convert CSV to XML (Python)
2012-12-17T16:16:04-08:00Tom Wissinghttp://code.activestate.com/recipes/users/4184629/http://code.activestate.com/recipes/578384-convert-csv-to-xml/
<p style="color: grey">
Python
recipe 578384
by <a href="/recipes/users/4184629/">Tom Wissing</a>
(<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/xml/">xml</a>).
</p>
<p>Convert CSV to XML.</p>
Ordered CSV read / write with colum based lookup (Python)
2012-03-02T12:45:29-08:00Gregory Nicholashttp://code.activestate.com/recipes/users/4180332/http://code.activestate.com/recipes/578059-ordered-csv-read-write-with-colum-based-lookup/
<p style="color: grey">
Python
recipe 578059
by <a href="/recipes/users/4180332/">Gregory Nicholas</a>
(<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/lookup/">lookup</a>).
</p>
<p>This allows you to hold on to your csv in a dict form, do lookups and modifications, and also write it in a preserved order. You can also change which column you want to be your lookup column (making sure that there is a unique id for every row of that column. In my example of usage, it assumes that both classes are contained withing the same file named 'CustomDictReader.py'</p>
Ordered CSV read / write with colum based lookup (Python)
2011-12-24T19:44:13-08:00__nerohttp://code.activestate.com/recipes/users/4177968/http://code.activestate.com/recipes/577996-ordered-csv-read-write-with-colum-based-lookup/
<p style="color: grey">
Python
recipe 577996
by <a href="/recipes/users/4177968/">__nero</a>
(<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/lookup/">lookup</a>).
</p>
<p>This allows you to hold on to your csv in a dict form, do lookups and modifications, and also write it in a preserved order. You can also change which column you want to be your lookup column (making sure that there is a unique id for every row of that column. In my example of usage, it assumes that both classes are contained withing the same file named 'CustomDictReader.py'</p>
Persistent dict with multiple standard file formats (Python)
2011-09-06T20:01:46-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/576642-persistent-dict-with-multiple-standard-file-format/
<p style="color: grey">
Python
recipe 576642
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
(<a href="/recipes/tags/dbm/">dbm</a>, <a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/persistent/">persistent</a>, <a href="/recipes/tags/shelve/">shelve</a>).
Revision 10.
</p>
<p>dbdict: a dbm based on a dict subclass.</p>
<p>On open, loads full file into memory.
On close, writes full dict to disk (atomically).
Supported output file formats: csv, json, and pickle.
Input file format automatically discovered.</p>
<p>Usable by the shelve module for fast access.</p>
Export Oracle Database to CSV using cx_Oracle (Python)
2010-07-11T19:49:42-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577304-export-oracle-database-to-csv-using-cx_oracle/
<p style="color: grey">
Python
recipe 577304
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/database/">database</a>).
</p>
<p>Creates a CSV file for each table in the target Oracle database.</p>
Correctly reading CSV files in arbitrary encodings (Python)
2011-07-25T07:29:08-07:00Devin Jeanpierrehttp://code.activestate.com/recipes/users/4178508/http://code.activestate.com/recipes/577778-correctly-reading-csv-files-in-arbitrary-encodings/
<p style="color: grey">
Python
recipe 577778
by <a href="/recipes/users/4178508/">Devin Jeanpierre</a>
(<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/unicode/">unicode</a>).
Revision 4.
</p>
<p>Recipe for using unicode files (i.e. files opened with <code>codecs.open</code>) with the csv module.</p>
Extract air quality data of Santigo , Chile on csv file (Python)
2011-06-30T13:39:29-07:00jrovegnohttp://code.activestate.com/recipes/users/4170207/http://code.activestate.com/recipes/577773-extract-air-quality-data-of-santigo-chile-on-csv-f/
<p style="color: grey">
Python
recipe 577773
by <a href="/recipes/users/4170207/">jrovegno</a>
(<a href="/recipes/tags/aire/">aire</a>, <a href="/recipes/tags/calidad/">calidad</a>, <a href="/recipes/tags/chile/">chile</a>, <a href="/recipes/tags/data_mining/">data_mining</a>, <a href="/recipes/tags/santiago/">santiago</a>).
</p>
<p>Extract air quality data of Santigo , Chile on csv file</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>
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>
webcheck: site to csv (Python)
2011-03-09T06:37:08-08:00Jervis Whitleyhttp://code.activestate.com/recipes/users/4169341/http://code.activestate.com/recipes/577602-webcheck-site-to-csv/
<p style="color: grey">
Python
recipe 577602
by <a href="/recipes/users/4169341/">Jervis Whitley</a>
(<a href="/recipes/tags/html/">html</a>, <a href="/recipes/tags/linkcheck/">linkcheck</a>, <a href="/recipes/tags/sitemap/">sitemap</a>, <a href="/recipes/tags/webcheck/">webcheck</a>).
Revision 3.
</p>
<p>An extension to Arthur de Jong's excellent webcheck tool (a website link checker) (<a href="http://arthurdejong.org/webcheck" rel="nofollow">http://arthurdejong.org/webcheck</a>) that will read in the resultant webcheck.dat file and create a csv formatted file.</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>
Aggregates using groupby, defaultdict and Counter (Python)
2011-02-07T15:38:09-08:00N Nhttp://code.activestate.com/recipes/users/1639254/http://code.activestate.com/recipes/577535-aggregates-using-groupby-defaultdict-and-counter/
<p style="color: grey">
Python
recipe 577535
by <a href="/recipes/users/1639254/">N N</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
Revision 2.
</p>
<p>How to emulate SQL aggregate functions AVG, COUNT, MAX, MIN and SUM on csv type data files using tools from the standard library.</p>
Query CSV file (Python)
2010-10-12T00:08:22-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577419-query-csv-file/
<p style="color: grey">
Python
recipe 577419
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/database/">database</a>).
Revision 4.
</p>
<p>The user can define a query expression for (almost) any CSV file.
(The first row assumed to contain column headers.)
Then the code outputs all data rows matching to the given query expression.</p>
Oracle Database Regex Search using cx_Oracle (Python)
2010-07-11T19:39:21-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577303-oracle-database-regex-search-using-cx_oracle/
<p style="color: grey">
Python
recipe 577303
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/database/">database</a>).
</p>
<p>Finds all database rows in all tables that contain any column which matches to given regex and outputs a CSV file for each table containing matches.</p>
Retrieve Dell Warranty Information for all machines in AD Domain (Python)
2010-02-18T15:51:28-08:00Kenneth Keiterhttp://code.activestate.com/recipes/users/4173089/http://code.activestate.com/recipes/577056-retrieve-dell-warranty-information-for-all-machine/
<p style="color: grey">
Python
recipe 577056
by <a href="/recipes/users/4173089/">Kenneth Keiter</a>
(<a href="/recipes/tags/active_directory_scripts/">active_directory_scripts</a>, <a href="/recipes/tags/ad/">ad</a>, <a href="/recipes/tags/dell/">dell</a>, <a href="/recipes/tags/domain/">domain</a>, <a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/warranty/">warranty</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>This snippet retrieves warranty information for all Dell machines in a domain and outputs a CSV of the results. </p>
<p>Should be run on a machine joined to an active directory or NT4 domain. May need to be updated to parse Dell's website if they update it (since they have no service tag API).</p>
Compare CSV Inventory files (Python)
2009-08-18T14:14:04-07:00Mike Burkehttp://code.activestate.com/recipes/users/4171487/http://code.activestate.com/recipes/576885-compare-csv-inventory-files/
<p style="color: grey">
Python
recipe 576885
by <a href="/recipes/users/4171487/">Mike Burke</a>
(<a href="/recipes/tags/compare/">compare</a>, <a href="/recipes/tags/csv/">csv</a>).
</p>
<p>Program will compare two CSV files using a unique ID field and save any changes to ID as well as two secondary fields (qty & price). The code was written to pick out updates from supplier inventory files.</p>
Simple conversion of excel files into CSV and YAML (Python)
2008-02-14T00:39:22-08:00Philip Kromerhttp://code.activestate.com/recipes/users/552075/http://code.activestate.com/recipes/546518-simple-conversion-of-excel-files-into-csv-and-yaml/
<p style="color: grey">
Python
recipe 546518
by <a href="/recipes/users/552075/">Philip Kromer</a>
(<a href="/recipes/tags/files/">files</a>).
</p>
<p>Takes an excel file, dumps out a series of CSV files (one for each sheet, named for the file and sheet) and a YAML file (an array of sheets, each sheet a dict containing the table_name and the table_data, a 2-d array of cell values).</p>
<p>Inspired by Bryan Niederberger's "Easy Cross Platform Excel Parsing With Xlrd", <a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/483742" rel="nofollow">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/483742</a> As opposed to his code, this script makes no attempt to understand the structure of the sheet (look for header cells, etc) -- it simply reads, converts, dumps.</p>
Update stock quote using Yahoo! Finance web services (Python)
2008-06-22T18:33:50-07:00Wai Yip Tunghttp://code.activestate.com/recipes/users/2382677/http://code.activestate.com/recipes/573471-update-stock-quote-using-yahoo-finance-web-service/
<p style="color: grey">
Python
recipe 573471
by <a href="/recipes/users/2382677/">Wai Yip Tung</a>
(<a href="/recipes/tags/excel/">excel</a>, <a href="/recipes/tags/math/">math</a>).
Revision 2.
</p>
<p>This script update the stock quote on your spreadsheet by fetching the latest quote from Yahoo!Finance web services. It uses the pywin32 library to update the cells on an Excel spreadsheet.</p>
Create SQL tables from CSV files (Python)
2010-02-24T13:47:36-08:00Matt Keranenhttp://code.activestate.com/recipes/users/38288/http://code.activestate.com/recipes/498130-create-sql-tables-from-csv-files/
<p style="color: grey">
Python
recipe 498130
by <a href="/recipes/users/38288/">Matt Keranen</a>
(<a href="/recipes/tags/database/">database</a>).
</p>
<p>Script generates CREATE TABLE statements based on the width of data present in comma delimited (csv) test files. Setting the correct datatypes (other than VARCHAR), is still a manual adventure.</p>
<h5>TODOs:</h5>
<ul>
<li>Eliminate '#N/A', '@NA' from data</li>
<li>Remove commas from numeric data</li>
<li>Check for duplicate column names</li>
<li>Create BCP format file or INSERT statements?</li>
</ul>