Write CSV
to_csv writes a DataFrame as text. Use index=False to leave out the row labels.
Example
import pandas as pd
import numpy as np
import io
df = pd.DataFrame({'a': [1, 2], 'b': ['x', 'y']})
buf = io.StringIO()
df.to_csv(buf, index=False)
print(buf.getvalue())Result
a,b 1,x 2,y
Exercise
Leave out the index.
df.to_csv("o.csv", index=)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.