I\'m trying to mix StringIO and BytesIO with pandas and struggling with some basic stuff. For example, I can\'t get \"output\" below to work, whereas \"output2\" below does
io.StringIO
here is behaving just like a file -- you wrote to it, and now the file pointer is pointing at the end. When you try to read from it after that, there's nothing after the point you wrote, so: no columns to parse.
Instead, just like you would with an ordinary file, seek
to the start, and then read:
>>> output = io.StringIO()
>>> output.write('x,y\n')
4
>>> output.write('1,2\n')
4
>>> output.seek(0)
0
>>> pd.read_csv(output)
x y
0 1 2