Tsallaka zuwa abun ciki
Justice Tech School

Read CSV

read_csv loads a CSV file or any text buffer into a DataFrame. Useful options are sep, header, names, usecols, index_col and dtype. Here StringIO stands in for a file.

Example
import pandas as pd
import numpy as np
import io
text = 'name,age\nAda,30\nBob,25\n'
df = pd.read_csv(io.StringIO(text))
print(df)
print(df.dtypes.astype(str).tolist())

Result

  name  age
0  Ada   30
1  Bob   25
['str', 'int64']

Exercise

Read a CSV.

pd.("data.csv")

Quiz Test

What does usecols do?

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