1. Learn
  2. /
  3. Courses
  4. /
  5. Intermediate Python for Finance

Exercise

Dropping columns from DataFrame

Sometimes your DataFrame has columns that you no longer need. It is often the case that you need to simplify a DataFrame by removing columns. Do you remember from the video which method you need to use to drop a row or a column?

Pretend that you wish to present the results of your PCE calculation to stakeholders at your company, without presenting the columns you used for the calculation. Drop the columns PCDG, PCND, and PCESV from the supplied DataFrame pce, leaving only the column PCE. The list columns_to_drop is provided.

Instructions

100 XP
  • Print the columns of the pce DataFrame.
  • Create a new DataFrame from pce without the columns in the list columns_to_drop.
  • Print the columns of the new DataFrame.
  • Drop the columns in columns_to_drop from the DataFrame pce in place.