Consider a data frame df with columns ['A', 'B', 'C', 'D'] and rows ['r1', 'r2', 'r3'], Which of the following expression is used to extract columns 'C' and 'D'?

Questions & AnswersCategory: Programming LanguageConsider a data frame df with columns ['A', 'B', 'C', 'D'] and rows ['r1', 'r2', 'r3'], Which of the following expression is used to extract columns 'C' and 'D'?
Adam asked 3 years ago

Consider a data frame df with columns [‘A’, ‘B’, ‘C’, ‘D’] and rows [‘r1’, ‘r2’, ‘r3’], Which of the following expression is used to extract columns ‘C’ and ‘D’?
a. df.loc[:, lambda x : x.columns.isin([‘C’, ‘D’])]
b. df[:, lambda x : x.columns.isin([‘C’, ‘D’])]
c. lambda x : x.columns.isin([‘C’, ‘D’])
d. None