Hi,
The "float_format" option that appears in the DataFrame.to_csv method is incredibly useful -- I was wondering when it got added to pandas? I see that "float_format" got added to the to string representation almost a year ago, way back in 0.6, but it looks like my pandas 0.8.1 does not have it for DataFrames:
$ python
Python 2.6.5 (r265:79063, Oct 1 2012, 22:04:36)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
>>> a = [{"a": 0.435, "b": 0.43423534634}]
>>> b = pandas.DataFrame(a)
>>> b.to_csv("test_float.txt", float_format="%.2f")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: to_csv() got an unexpected keyword argument 'float_format'
>>> pandas
<module 'pandas' from '/usr/local/lib/python2.6/dist-packages/pandas-0.8.1-py2.6-linux-x86_64.egg/pandas/__init__.pyc'>
Did this method only get added after 0.8.1? I'm asking because many users of the code I'm writing have pandas 0.8.* and will not want to upgrade, so if it's a very new addition, I was hoping someone could recommend a hackier way that is compatible with older pandas releases like 0.8.* to reformat the floats with 'to_csv'. Is there a simple way to do it, or is the answer just not to use 'to_csv' for this and instead serialize the df by hand? Thanks.