how to get only certain columns in pandas

df1 = df.iloc[:,0:2] # Remember that Python does not slice inclusive of the ending index.

Here is what the above code is Doing:
1. We’re using the .iloc[] method to select the first two columns of the df DataFrame.
2. We’re assigning the resulting DataFrame to a new variable, df1.