DataFrame
Explore the fundamentals of Pandas DataFrames including creation, indexing, selecting rows and columns, adding and deleting columns, and conditional filtering. This lesson helps you efficiently manage and analyze structured data using key DataFrame methods.
A very simple way to think about a DataFrame is as a bunch of Series that share the same index. A DataFrame is a rectangular table of data that contains an ordered collection of columns, each of which can be a different value type (numeric, string, boolean, and so on). A DataFrame has both row and column indexes. It can be thought of as being a dictionary of Series, all of which share the same index (any row or column).
Let’s create a few DataFrames to learn more about them.
For our DataFrame, we’ll create two labels or indexes:
- Our index will be for rows
r1tor10. - Our columns will be for columns
c1toc10.
In the code below, we’ll use split() to create a list and then use arange() and reshape() together to create a 2D array (matrix).
Now, let’s create our first DataFrame using index, columns, and array_2d.
Our first data frame is df. We have columns c1 to c10 and their corresponding rows r1 to r10. Each column is actually a pandas Series, sharing a common index of row labels.
Use df to access and manipulate data, a core concept in this course.
Columns
Grabbing columns from DataFrame
To grab a column from a DataFrame, we simply pass the name of the required column in square brackets.
The output is a Series. The returned Series shares ...