StringIO and pandas read_csv

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)