pandas drop all columns except certain ones

df.drop(df.columns.difference(['a','b']), 1, inplace=True)

Here is what the above code is Doing:
1. First, we create a list of all the columns that we want to keep.
2. Then, we use the drop() method to drop all the columns that are not in the list.
3. Finally, we set the inplace parameter to True to make the changes in the original DataFrame.