Friday, January 02, 2009

Using CSV files in Python

It is often desirable to store experimental data in Comma Separated Value (CSV) files so that we can easily inspect/process them with a text editor or more advanced data management/analysis software (like Microsoft Excel).

There are a number of ways of reading/writing CSV files in Python.

  • Python's string and file functions are adequate for simple CSV files (e.g., those with only numeric data).

  • Using the standard module csv.

  • Using the numpy functions loadtxt/savetxt.

  • Using the matplotlib.mlab functions such as load/save and csv2rec/rec2csv.

No comments: