File I/O

Read from and write to different types of files in pandas.

Chapter Goals:

  • Learn how to handle file input/output using pandas
  • Write code for processing data files

A. Reading data

One of the most important features in pandas is the ability to read from data files. pandas accepts a variety of file formats, ranging from CSV and Excel spreadsheets to SQL and even HTML. A full list of the available file formats for pandas can be found here.

In this chapter we'll focus on three of the most common file types: CSV, XLSX (Microsoft Excel), and JSON. For reading data from a file, we use either the read_csv, read_excel, or read_json function, depending on the file type.

Each of the file reading functions takes in a file path as the only required ...