Tsallaka zuwa abun ciki
Justice Tech School

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

Why index=False?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.