Work With ColumnsWork With Columns

By working with the dataframe, we can access each column separately. Let's look at the syntax.

We can see the next syntax for this:

  • First, write the name of the dataframe we are working with.
  • Then, in square brackets we put the name of the column we want to have access to. Please note that the name of the column must be in quotation marks.

Let's look at an example on a dataframe.

If we run this code, we will see that instead of a whole dataframe, we will see only a column with capitals.

Let's look at how to access multiple columns.

Compared to the previous example, we see only two differences. This time you need to place the list of columns that you want to get within square brackets, which means you will use double square brackets. Look at the example below.


Output the columns 'model', 'year', and 'price' (in that order) of the audi_cars dataframe. Let's try it!

Everything was clear?

Section 1. Chapter 11
toggle bottom row