Read CSV into a DataFrame

Summary: in this tutorial, you’ll learn how to create a DataFrame directly from CSV files.

CSV stands for comma-delimited values and is the most common format for storing data. You can use most any other type of delimiter-based file, for example, TSV – tab-separated values.

We can even create DataFrame with simple TXT files, if the data inside is separated with a delimiter.

Read CSV

For reading CSV, we use Pandas read_csv method.

import pandas as pd
dframe = pd.read_csv("example.csv")

Output :


Read TSV

TSV is just another variation of CSV, specifically it use a tab as the delimiter instead of a comma.

In order to read TSV into a DataFrame, we use the same read_csv method, but pass an additional delimiter parameter.

import pandas as pd
dframe = pd.read_csv("example.tsv", delimiter="\t")

In this example, \t is the Python way of writing a tab. The output is still the same.

Author: Thijmen I’m currently a SysAdmin located in the Netherlands. Every day I try to keep around a hundred users happy with their network connections and overall, tech-related issues. I also spend my spare time fiddling with web-based applications.
See also  Pandas Axis and Labels

Leave a Comment