Understand the idea
Make a separate working table before editing. Assigning another name to df alone still refers to the same object.
A small example
clean = df.copy() lets you select or sort clean while keeping the original df available.
Follow the code
Apply the idea to the supplied table. Read from top to bottom; the final line displays the result.
clean = df.copy()
clean = clean[["candy", "price"]]
cleanWhat each part does
clean =- name for the working table
df.copy()- make a separate DataFrame
Other choices for later exercises
clean["price"] =- replace a column in the copy
Your inputs
The editable setup on the right creates df. Run executes the setup and your work from top to bottom.
| candy | flavour | price | rating | shelf |
|---|---|---|---|---|
| Gummy Bear | fruity | 1.2 | 4.1 | A |
| Choco Pop | chocolate | 2.1 | 4.6 | B |
| Mint Bite | mint | 1.5 | 3.8 | A |
| Berry Loop | fruity | 2.8 | 4.4 | B |
| Cocoa Cube | chocolate | 3.4 | 4.9 | A |
| Lemon Drop | fruity | 1.8 | 4 | B |
Your task · Follow
- Prepare a separate price-list copy named clean from df.
- Keep candy and price in that order; leave the original df intact and display clean.
Hint
Make the copy before preparing the handoff.
Reveal solution
One way to do it. Keep any supplied setup in the editor and use this in the Your work section.
clean = df.copy()
clean = clean[["candy", "price"]]
clean