CSV Round Trip
to_csv writes and read_csv reads. Use index=False to skip the index.
Example
import io
df = pd.DataFrame({"a": [1, 2], "b": ["x", "y"]})
text = df.to_csv(index=False)
print(text)
back = pd.read_csv(io.StringIO(text))
print(back.equals(df))Result
a,b 1,x 2,y True
Exercise
Write a CSV.
df.("f.csv")
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.