Professional Documents
Culture Documents
03 - Introduction To Pandas 5
03 - Introduction To Pandas 5
This DataFrame is being used to explain how to add, remove and insert rows and columns into a DataFrame.
In [ ]: d = np.arange(16).reshape(4,4)
cols = ['one','two','three','four']
df
loc gets rows or columns with particular labels from the index.
iloc gets rows or columns at particular positions in the index (so it only takes integers).
loc and iloc take 2 arguments - row, column
the column argument defaults to all columns
df.loc['c']
df.iloc[2]
df.loc[:, 'three']
df.iloc[:, 2]
df.loc['c','three']
df.iloc[2,2]
df['one']
df[['two','three']]
df[['three','two']]
df.drop('b')
# Note that dropping returns a new DataFrame, the original is still unchanged