Skip to main content
  1. Posts/

Introduction to Pandas — Working with CSV

·1 min
Python Python Basics Pandas Csv Data
Table of Contents

Reading CSV Files
#

Reading a CSV file in Pandas is very straightforward. All you need is:

df = pd.read_csv("path")

This single line loads the CSV file. By default, Pandas uses the first row of the file as column headers. If the CSV file has no header row, you can specify:

df = pd.read_csv("path", header=None)

By default, the first column is not used as the index. If you want to use a specific column as the index:

df = pd.read_csv("path", index_col="column_name")

Displaying Data
#

When the file contains many columns, Pandas may truncate the display and hide some columns. If you want to see all columns, you can use:

pd.set_option("display.max_columns", num)

Where num is the number of columns you want to show.

Sometimes, a column contains values that are too long and get truncated. To change the maximum column width shown:

pd.set_option("display.max_colwidth", num)

Related

Introduction to Pandas — DataFrame
·3 mins
Python Python Basics Pandas Data
Introduction to Pandas — Series
·3 mins
Python Python Basics Pandas Data
Introduction to Numpy
·3 mins
Python Python Basics Numpy Data