How is a Pandas series different from a dataframe?


#1

Question

How is a Pandas series different from a dataframe?

Answer

In Pandas a series is a one-dimensional object that contains any type of data, similar in ways to a Numpy array.

Series objects have a single axis label, like a column title, which is the index of the series. A series is essentially a single column.

# Creating a series
clinic_east = pd.Series([100, 51, 81, 80, 51, 112])

A dataframe is a two-dimensional object that can hold multiple columns of different types of data. They are similar to a table in SQL.

A single column of a dataframe is a series, and a dataframe is a container of two or more series objects.

# Creating a DataFrame
df = pd.DataFrame ([
  ['January', 100, 100],
  ['February', 51, 45],
  ['March', 81, 96]],
  columns=["month", "clinic_east", "clinic_north"]
)