Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Add a New Column 1/2 | The Very First Steps
course content

Conteúdo do Curso

Pandas First Steps

Add a New Column 1/2Add a New Column 1/2

We've learned how to create a DataFrame. Now let's explore what we can do with it.

First, let's craft a compact DataFrame consisting of three columns and seven rows.

You can expand the DataFrame by adding new columns, and there are multiple ways to do it. We'll focus on two methods. The syntax for the first method is as follows:

  • dataframe is the name of our existing DataFrame to which we'll add new columns;
  • name_of_new_column is the name you're giving to the new column you're adding.;
  • value_1, value_2, value_3 are the values that will populate the new column.

Note

The name of the new column should be enclosed in quotation marks and wrapped in square brackets. Likewise, the values inserted into the new column should also be within square brackets. If the values are numeric, they don't need to be in quotes; if they're strings, then quotes are necessary.

Now, let's demonstrate how to add a population column to our pre-existing countries DataFrame.

Note

Using this method, the new column will be appended to the end of the DataFrame.

Tudo estava claro?

Seção 1. Capítulo 7
course content

Conteúdo do Curso

Pandas First Steps

Add a New Column 1/2Add a New Column 1/2

We've learned how to create a DataFrame. Now let's explore what we can do with it.

First, let's craft a compact DataFrame consisting of three columns and seven rows.

You can expand the DataFrame by adding new columns, and there are multiple ways to do it. We'll focus on two methods. The syntax for the first method is as follows:

  • dataframe is the name of our existing DataFrame to which we'll add new columns;
  • name_of_new_column is the name you're giving to the new column you're adding.;
  • value_1, value_2, value_3 are the values that will populate the new column.

Note

The name of the new column should be enclosed in quotation marks and wrapped in square brackets. Likewise, the values inserted into the new column should also be within square brackets. If the values are numeric, they don't need to be in quotes; if they're strings, then quotes are necessary.

Now, let's demonstrate how to add a population column to our pre-existing countries DataFrame.

Note

Using this method, the new column will be appended to the end of the DataFrame.

Tudo estava claro?

Seção 1. Capítulo 7
some-alt