4 The DataFrame object

This chapter covers

  • Instantiating DataFrame objects from dictionaries and NumPy ndarrays
  • Importing DataFrames from CSV files with the read_csv function
  • Sorting DataFrame columns
  • Accessing rows and columns in a DataFrame
  • Setting and resetting a DataFrame index
  • Renaming columns and index labels in a DataFrame

The pandas DataFrame is a two-dimensional table of data with rows and columns. As with a Series, pandas assigns an index label and an index position to each DataFrame row. Pandas also assigns a label and a position to each column. The DataFrame is two-dimensional because it requires two points of reference—a row and a column—to isolate a value from the data set. Figure 4.1 displays a visual example of a pandas

Get Pandas in Action now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.