#!/usr/bin/env python # coding: utf-8 # - Import Package # We import the pandas package with the alias pd # - Import Data # We import the Boston Dataset from # - Select Data by Row number # - Select Data by Column Name # - Select Data by Row and Column # - Select Data by Condition # In[3]: import pandas as pd # In[4]: Boston =pd.read_csv("http://vincentarelbundock.github.io/Rdatasets/csv/MASS/Boston.csv") # In[5]: Boston.head(5) #Gives first few rows. In R we typically use head(object) while in Python we would use object.head() # In[8]: Boston=Boston.drop('Unnamed: 0', 1) #Dropping a particular variable # In[9]: Boston.dtypes # In[10]: Boston.info()# Gives information of object. In R this is given by str # In[12]: type(Boston) #Gives type of object. In R this is given by class # In[16]: Boston.shape #Gives rows and columns. In R this is given by dim # In[13]: dir(Boston) #What are the various commands we can run on Boston # In[17]: Boston[0:3] #Gives rows from first row to third row. In python index starts from 0 while in R it starts from 1. # In[21]: Boston[-5:504] #Gives rows from 506(total rows)-5 to the row number specified. #Note index is one less than row number unlike R # In[25]: Boston[['medv','rm','chas']].head() #Note the double square brackets [[]] # In[28]: Boston.ix[3:10,['medv','rm','chas','nox']] #Note the use of command ix as well as putting row numbers and column names seperately # In[39]: Boston['medv']>49 # In[38]: Boston[Boston['medv']>49] # In[47]: Boston[Boston['medv']>49 ][Boston['chas']==0] # In[48]: Boston.query('medv >49 and rm >8') # In[52]: Boston.query('medv >49 or rm <4') # In[54]: # In[ ]: