I'm using jupyter notebook pandas to_csv
doesn't output the dataframe to a file.
I tried to use to_csv
to output a dataframe to a csv file by setting the working directory or specify the directory, and it didn't create any file. The code ran and didn't produce any error message, but when I opened the folder, there was no such file.
I tried a different IO, and it did show the result had been output.
from io import StringIO
output = StringIO()
a.to_csv(output)
print(output.getvalue())
I got the following output:
,a
0,1
1,2
2,3
but again to_csv('filepath/filename.csv')
doesn't output any file.
PS: I can read any file in any directory using read_csv().
Update
If I save the file df.to_csv('testfile.csv')
then do pd.read_csv('testfile.csv')
I can read the file but cannot see it in the directory.
Also, doing [x for x in os.listdir() if x == 'testfile.csv']
will list the file.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…