In [2]:
import pandas as pd
In [3]:
#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
Out[3]:
In [10]:
#Size of dataframe
df.shape
Out[10]:
In [11]:
#Transposing a dataframe
df.T
Out[11]:
In [7]:
#Dropping a column
#axis=1 is for column
df.drop(['age'], axis=1)
Out[7]:
In [8]:
#If you dont'put inplace the orginical df remains same
df
Out[8]:
In [9]:
#Dropping a row
#axis=0 for row
df.drop([1], axis=0)
Out[9]:
In [14]:
#Scalar addition
df['big_age'] = df['age'] + 10
df
Out[14]:
In [17]:
#we can add two columns
#Think it as matrix addition
df['bigger_age'] = df['age'] + df['big_age']
df
Out[17]:
In [19]:
#Scalar multiplication
df['biggest_age'] = df['age']*10
df
Out[19]: