discoveries in digital audio, music notation, and information encoding

Archive for the ‘CSV’ tag

just goofin’ with a little Python CSV function and a limerickesque

leave a comment

This is probably a total waste of anyone's time but  …

The other night, after I'd worked on the Aguado Rondo (Op. 2, #2), I started goofing around with a little Python function that would turn a delimited text file into a Python dictionary, allowing me to target a specific cell in a delimited file, i.e. a "spreadsheet", without using the CSV module.

It works (well, at least I hope it does) this way:

films = csv2dict("films.txt", ";") #pass filename and delimiter
print films["title"] #print "title" column sans the header
print films["title"][-1] #prints last cell in the "title" column

It seems helpful to be able to do this. I've tested it with a UTF-8 file to write to file with some accent markings on people's names, etc. but I'm pretty sure it'll break on stuff I haven't thought of.

Anyway, maybe it'll come in handy to me for something.

Here's the function:

def csv2dict(fileName, delimiter):	
  f = open(fileName, "r") #open file
  lines = #read file
  f.close() #close file
  rows = lines.split("\n") #put lines in list
  headers = rows[0].split(delimiter) #put header titles in list
  rows.pop(0) #remove header from "rows" list

  i = 0
  worksheet = {}
  for header in headers: #for each header, i.e. each column
    columnCells = []
    for row in rows: #for each non-header row in delimited file
      if row != "":
        rowCells = row.split(delimiter) #get cells in row
        columnCells.append(rowCells[i]) #put column's cells in list
    worksheet[header] = columnCells #set header as KEY and set "columnCells" list as VALUE
    i = i + 1

  return worksheet

And for any guitarists out there, here's a little silly rhyme I wrote when living in my home eternal, Charleston, SC. I know the Sor as "warrior against the French" thing isn't accurate, but it helps the punchline.


The title is, of course, that as Sor's famous duet.

"Le Deux Ami"

Fernando Sor,
who served in the war,
fought Bonaparte in the army.

But Dionisio Aguado,
who lacked such bravado,
preferred to run home to his mommy.

Related Content:

Written by nitin

February 16th, 2012 at 8:44 pm

PubMed CSV option added

leave a comment

It looks like things are afoot at They've apparently added a CSV option for downloading citations. This is great and will facilitate people getting citations into spreadsheets. Having this new option sure beats that FLink thing.

I'm not sure it's totally up and running though as the RSS feed for their News and Noteworthy shows a link to a post called "CSV File Selection" from March 24th but there's no post there, it just redirects to the home page.

Interestingly, this all seems to have happened a few days after someone from the NIH – according to Google Analytics – spent a good bit of time on this blog looking for information on how to get PubMed citations into a spreadsheet. Boy, would I like to believe that had something to do with it!

Of course, the data in the CSV file is still limited and non-customizable. You still can't get abstracts, it seems. That makes no sense of course since it is available in the XML format. If they've already got the data in a granular fashion, why not offer users better options?

For now, if you want abstracts and customized output you can try PubMed2XL. By the way, I'll be uploading an updated version in a few days. I just moved to a new town and I'm not quite settled enough to update some documentation and do some light programming work.


Related Content:

Written by nitin

March 31st, 2011 at 10:04 am

Posted in news

Tagged with ,