The following code throws that error:
In [1]: import pandas as pd
In [2]: import numpy as np
In [3]: df = pd.DataFrame(np.random.randn(10, 5), columns=['a', 'b', 'c', 'd', 'e'])
In [4]: import tempfile
In [5]: tf = tempfile.NamedTemporaryFile()
In [6]: df.to_csv(tf)
Am I missing something?
You'll want tf = tempfile.NamedTemporaryFile(mode='w') or wt since you're writing text, not bytes. Check if that works for you?
It does. Thanks!
On Mon, Jan 11, 2016 at 2:41 PM, Tom Augspurger [email protected]
wrote:
You'll want tf = tempfile.NamedTemporaryFile(mode='w') or wt since you're
writing text, not bytes. Check if that works for you?—
Reply to this email directly or view it on GitHub
https://github.com/pydata/pandas/issues/12018#issuecomment-170714634.
df.to_csv(tf)
how to read after this line?? i need to read tf, also need to mail the csv file
how to check whether df.to_csv(tf) is properly exported as csv, df has data , tf has data may be not how to read and print tf?
@balaprasad18 You might try searching on stackoverflow under the pandas tag.
Most helpful comment
You'll want
tf = tempfile.NamedTemporaryFile(mode='w')orwtsince you're writing text, not bytes. Check if that works for you?