#!/usr/bin/env python # coding: utf-8 # In[1]: import pandas as pd # In[2]: #Read the csv file titanic_df = pd.read_csv('titanic.csv') #It's a big file so let's extract a small data out of it df = titanic_df.loc[[0,1,2,3,4,5],['name','sex','age','fare']] df # In[3]: #Let's just print the name df.name # In[4]: #we can print the name using loc also df.loc[:,'name'] # In[5]: #iloc can be used with positional integers #First two rows and all columns df.iloc[0:2,:] # In[6]: #all rows and last column df.iloc[:,-1] # In[7]: #show the index df.index # In[8]: #using criteria to filter df[df.sex == 'female'] # In[9]: df[df.index == 2] # In[10]: #we can use conditions df[(df.sex == 'female') & (df.age >= 20)]