2

I'm having trouble writing the entries of a pandas dataframe to a stringbuffer.

It's possible to initialize a dataframe by passing a 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]: 
   a  b
0  1  2

To do the opposite is not straight forward as the DataFrame.to_csv function only accepts a string file path.

Is there any good reason for this behaviour? What's the best way to serialize a pandas DataFrame without storing the contents on disk first?

1 Answer 1

3

This is pretty much just an oversight / inconsistency. I created a GitHub issue here for it:

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

EDIT: Implemented this today so you can pass a StringIO to to_csv, in git master now and will be part of forthcoming 0.7.0 release

Sign up to request clarification or add additional context in comments.

1 Comment

link to issue is broken

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.