Deleting unwanted data
After adding that data to our dataframe in the previous section, we can see the need to delete unwanted data. We need a way to undo our mistakes and get rid of data that we aren't going to use. Like adding data, we can use dictionary syntax to delete unwanted columns, just as we would when removing keys from a dictionary. Both del df['<column_name>'] and df.pop('<column_name>') will work, provided that there is indeed a column with that name; otherwise, we will get a KeyError. The difference here is that while del removes it right away, pop() will return the column that we are removing. Remember that both of these operations will change our original dataframe, so use them with care.
Let's use dictionary notation to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access