Fist step to Python Pandas library¶
Loading pandas¶
In [3]:
# this is a comment
import pandas as pd
In [8]:
# creating a series
# A one dimentional array
s = pd.Series([3,5,5,9,6,8])
s
Out[8]:
In [9]:
# returning the first 5 element of a series
s.head()
Out[9]:
Reading data from URL¶
In [12]:
ufo = pd.read_table('http://bit.ly/uforeports', sep=',')
In [13]:
ufo.head()
Out[13]:
In [16]:
# columns can be access as array or as obje
# ufo['State'] === ufo.State
ufo.State
Out[16]:
In [29]:
# add a new row to the table
ufo['Address'] = ufo['City'] + ' ' + ufo.State
ufo.head()
Out[29]:
In [30]:
# see the shap of the data ( number of rows and columns)
ufo.shape
Out[30]:
In [31]:
# to see data type of each columns
ufo.dtypes
Out[31]:
In [26]:
# view columns
ufo.columns
Out[26]:
In [32]:
# drop colums[col1, col2, ..., coln]
ufo.drop(['Address'], axis=1, inplace=True)
ufo.head()
Out[32]:
In [36]:
# sort a column of table
ufo.State.sort_values(ascending=True).head()
Out[36]:
In [37]:
# sort table base on specific column
ufo.sort_values('City').head()
Out[37]: