Conteúdo do Curso
Pandas: First Steps
Pandas: First Steps
1. Getting Started
Introduction to PandasSeriesTask: Coffee Orders SeriesTask: Barista's Favorites CoffeesAccessing Elements from a SeriesTask: Drink of the HourTask - Signature DrinksTask: Mid-Morning SpecialsTask - Fetching the Mid-Shift DrinksOperations over SeriesTask: Modifying a single elementTask: Modifying the Entire SeriesTask: Modifying Part of a SeriesTask: Processing the Restock of Inventory
2. Basics of Dataframes
What is a DataFrame?Task: Creating a Table of Popular Coffee DrinksTask: Tracking Coffee Bean DeliveriesTask: Weekly Coffee Sales ReportAdding new ColumnsTask: Finding Total Sales Per DrinkTask: Calculating Total Sales RevenueAdding new RowsTask: Adding a New Employee to the Café TeamTask: Adding New Coffee Types to the Café Menu
3. Fetching Data from DataFrames
The `head()` MethodTask: Preview the Coffee MenuThe `tail()` MethodTask: Finding the Most Expensive CoffeesThe `sample()` MethodTask: Randomly Select Customer Orders for Quality CheckExtracting Multiple ColumnsTask: Extracting the Total ProfitTask: Extract Sales Data For AnalysisThe `iloc` PropertyTask: Access Sales Data at Café Pandasia - Part 1Task: Access Sales Data at Café Pandasia - Part 2Task: Access Sales Data at Café Pandasia - Part 3
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:
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)
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 3. Capítulo 7