Starting with 0.21.0, using .loc
or []
with a list with one or more missing labels is deprecated in favor of .reindex
. So, the answer to your question is:
df1 = df.reindex(columns=['b','c'])
In prior versions, using .loc[list-of-labels]
would work as long as at least one of the keys was found (otherwise it would raise a KeyError
). This behavior is deprecated and now shows a warning message. The recommended alternative is to use .reindex()
.
Read more at Indexing and Selecting Data.