Pandas Serialization DataFrame

I am having trouble writing pandas frame entries to stringbuffer.

You can initialize the dataframe by passing the stringbuffer to the read_csv function.

In [80]: buf = StringIO('a,b\n1,2\n') In [81]: df = pandas.read_csv(buf) In [82]: df Out[82]: ab 0 1 2 

To do the opposite is not direct, since the DataFrame.to_csv function accepts only the path to the string file.

Are there any good reasons for this behavior? What is the best way to serialize a pandas DataFrame without first saving the contents to disk?

+2
source share
1 answer

This is pretty much just oversight / inconsistency. I created a GitHub problem here:

https://github.com/wesm/pandas/issues/765

EDIT: implemented today, so you can pass StringIO to to_csv , in git master now and will be part of the upcoming version 0.7.0

+4
source

All Articles