import seaborn as sns import pandas as pd %matplotlib inline pd.options.display.max_rows = 10 data = sns.load_dataset("titanic")
data
891 rows × 15 columns
The way I try to remember this is 1 looks like a column so 1 is for columns.
data.drop(labels = "alone",axis = 1)
891 rows × 14 columns
data.drop(labels =['class','who','fare'], axis = 1 )
891 rows × 12 columns
data.drop(labels =['class','who','fare'], axis = 1 ,inplace = True)
well remember columns parameter, we can do many things with that and pass the result to the drop method.
Let's look at a solid example
## very usefull one liner for you to understand columns and drop method. #1.get the position of the last two columns by accessing len() which gives the length or the number of elements in the list. #2.subtract 2 to get the last remaining #3.pass the integer as slice to the columns method to get the actual labels of the columns #4. finally used the labels to delete column names , by the drop method, data.drop(data.columns[len(data.columns)-2:],1)
891 rows × 13 columns