import seaborn as sns import pandas as pd %matplotlib inline pd.options.display.max_rows = 10 data = sns.load_dataset("titanic")
I want to make this as simple as possible, let's take a look at the data below and see where columns are.
data.head()
I am going to take columns age , sibsp and parch from the middle and move them all the way to then end. to do this I used the loc method, I convered some theory about loc in my filtering tutorial. loc method is a powerful method and you can do and should do so much with it.
data.loc[:,['survived', 'pclass', 'sex', 'fare', 'embarked', 'class', 'who', 'adult_male', 'deck', 'embark_town', 'alive', 'alone', 'age', 'sibsp', 'parch'] ]
891 rows × 15 columns
Let's recap on what the loc method is doing above, just to eradicate any confusion there might be.
so we have df.loc[] loc stands for location and the first argument is the row location followed by a comma and then the columns location. if you don't pass in the comma it will assume it's the row location. df.loc[rowlocation , columnslocation] rowlocation and column location can be list of rows and columns, slices of rows and columns labels to use slices for raw index use iloc