Python Language Reading and Writing CSV Using pandas

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Write a CSV file from a dict or a DataFrame.

import pandas as pd

d = {'a': (1, 101), 'b': (2, 202), 'c': (3, 303)}
pd.DataFrame.from_dict(d, orient="index")
df.to_csv("data.csv")

Read a CSV file as a DataFrame and convert it to a dict:

df = pd.read_csv("data.csv")
d = df.to_dict()


Got any Python Language Question?