Get startedGet started for free

Creating new columns

Personal consumption expenditures (PCE) are a measurement of consumer consumption useful in judging the state and direction of the economy. Pretend that you are a financial analyst at an investment fund tasked with calculating PCE. PCE is the sum of consumption by consumers of durable goods (PCDG), non-durable goods (PCND), and services (PCESV). Let's calculate PCE using the list pcesv, the DataFrame pcnd, and PCDG from a CSV file.

This exercise is part of the course

Intermediate Python for Finance

View Course

Exercise instructions

  • Create a column named PCESV from a list of values pcesv.
  • Create a column named PCND from the DataFrame pcnd.
  • Use the function .read_csv() to create a column named PCD' from the CSV file pcdg.csv.
  • Create a new column named PCE by adding other columns together.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Use the list pcesv to create the column PCESV
pce[____] = pcesv

# Use the DataFrame pcnd to create the column PCND
____ = pcnd

# Create column for PCDG using Pandas read_csv
pce['PCDG'] = pd.____('pcdg.csv', index_col='DATE')

# Create a column PCE by adding values from other columns
pce['PCE'] = pce['PCDG'] ____ pce['____'] + ____
pce.head()
Edit and Run Code