import pandas as pd import seaborn as sns pd.options.display.max_rows = 10 df = sns.load_dataset("titanic")
df.head()
type(df["survived"])
pandas.core.series.Series
type(df.survived)
type(df[["survived"]])
pandas.core.frame.DataFrame
df["survived"]
0 0 1 1 2 1 3 1 4 0 .. 886 0 887 1 888 0 889 1 890 0 Name: survived, Length: 891, dtype: int64
df.survived
df[["survived"]]
891 rows × 1 columns
df[["survived","fare"]]
891 rows × 2 columns
df.loc[:,["survived"]]
df.loc[:,["survived","fare","sex"]]
891 rows × 3 columns
df.loc[:,["sex","survived","fare"]]
# This will return everything df.iloc[:, : ]
891 rows × 15 columns
df.iloc[:, 0:3]
We can replicate the iloc operation for columns by accessing the columns index from the columns property as shown below:
df[df.columns[[0,5,4]]]