oldoc63 / learningDS

Learning DS with Codecademy and Books
0 stars 0 forks source link

Select Columns #372

Open oldoc63 opened 2 years ago

oldoc63 commented 2 years ago

Now we know how to create and load data. Let's select parts of those datasets that are interesting or important to our analyses.

Suppose you have the DataFrame called customers, which contains the ages of your customers:

oldoc63 commented 2 years ago

Perhaps you want to take the average or plot a histogram of the ages. In order to do either of these tasks, you'd need to select the column.

There are two possible syntaxes for selecting all values from a column:

  1. Select the column as if you were selecting a value from a dictionary using a key. In our example, we would type customers['age'] to select the ages.
  2. If the name of a column follows all of the rules for a variable name (doesn't start with a number, doesn't contains spaces or special characters, etc), then you can select it using the following notation: customers.age

When we select a single column, the result is called a Series.