Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Extracting Multiple Columns | Fetching Data from DataFrames
Pandas: First Steps
course content

Conteúdo do Curso

Pandas: First Steps

Pandas: First Steps

1. Getting Started
2. Basics of Dataframes
3. Fetching Data from DataFrames

book
Extracting Multiple Columns

We can fetch a single column from a DataFrame using the following syntax:

js

Note

When we fetch a single column, it is fetched in the form of a Series. Hence, all the methods and properties of a series are applicable to it.

It's possible to extract multiple columns from a DataFrame using the following syntax:

js

Where column1, column2, and so on, represent the names of the columns in string format.

The following example demonstrates the usage:

12345678910111213141516
import pandas as pd # Create a sample DataFrame with sales data df = pd.DataFrame({ 'Order ID': [101, 102, 103, 104], 'Customer Name': ['Alice', 'Bob', 'Charlie', 'David'], 'Amount Paid': [50.0, 30.0, 75.0, 40.0], 'Product': ['Laptop', 'Phone', 'Tablet', 'Monitor'], 'Purchase Date': ['2025-04-01', '2025-04-01', '2025-04-01', '2025-04-01'] }) # Extract specific columns from the DataFrame selected_columns = df[['Order ID', 'Customer Name', 'Amount Paid']] # Print the extracted columns print(selected_columns)
copy
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 7

Pergunte à IA

expand
ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

course content

Conteúdo do Curso

Pandas: First Steps

Pandas: First Steps

1. Getting Started
2. Basics of Dataframes
3. Fetching Data from DataFrames

book
Extracting Multiple Columns

We can fetch a single column from a DataFrame using the following syntax:

js

Note

When we fetch a single column, it is fetched in the form of a Series. Hence, all the methods and properties of a series are applicable to it.

It's possible to extract multiple columns from a DataFrame using the following syntax:

js

Where column1, column2, and so on, represent the names of the columns in string format.

The following example demonstrates the usage:

12345678910111213141516
import pandas as pd # Create a sample DataFrame with sales data df = pd.DataFrame({ 'Order ID': [101, 102, 103, 104], 'Customer Name': ['Alice', 'Bob', 'Charlie', 'David'], 'Amount Paid': [50.0, 30.0, 75.0, 40.0], 'Product': ['Laptop', 'Phone', 'Tablet', 'Monitor'], 'Purchase Date': ['2025-04-01', '2025-04-01', '2025-04-01', '2025-04-01'] }) # Extract specific columns from the DataFrame selected_columns = df[['Order ID', 'Customer Name', 'Amount Paid']] # Print the extracted columns print(selected_columns)
copy
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 7
Sentimos muito que algo saiu errado. O que aconteceu?
some-alt