MulaiMulai sekarang secara gratis

Creating columns

Sometimes we have to create new columns based on the data we have in order to better represent the information we currently have. For example, maybe we care more about the dollar value of our ticket sales than just the actual quantity of tickets we've sold.

Latihan ini adalah bagian dari kursus

Python for Spreadsheet Users

Lihat Kursus

Petunjuk latihan

  • Create a new column in sales called sales_usd, equal to ticket_quantity multiplied by 20.
  • Print the head of sales.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Import the pandas package as pd
import pandas as pd

# Read in the Excel file
sales = pd.read_excel('ticket_sales.xlsx')

# Create a sales_usd column
sales[____] = sales[____] * ____

# Print the head of sales
Edit dan Jalankan Kode