Introduction to Pandas for Data Analysis

pandas is a software library written for the Python programming language for data manipulation and analysis

Installing Pandas

# pip2 install pandas
Collecting pandas
Downloading pandas-0.19.2-cp27-cp27mu-manylinux1_x86_64.whl (17.2MB)
100% |████████████████████████████████| 17.2MB 44kB/s
Collecting numpy>=1.7.0 (from pandas)
Downloading numpy-1.12.1-cp27-cp27mu-manylinux1_x86_64.whl (16.5MB)
100% |████████████████████████████████| 16.5MB 69kB/s
Requirement already satisfied (use — upgrade to upgrade): python-dateutil in /usr/lib/python2.7/site-packages (from pandas)
Collecting pytz>=2011k (from pandas)
Downloading pytz-2016.10-py2.py3-none-any.whl (483kB)
100% |████████████████████████████████| 491kB 2.6MB/s
Requirement already satisfied (use — upgrade to upgrade): six>=1.5 in /usr/lib/python2.7/site-packages (from python-dateutil->pandas)
Installing collected packages: numpy, pytz, pandas
Successfully installed numpy-1.12.1 pandas-0.19.2 pytz-2016.10
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the ‘pip install — upgrade pip’ command.

Now to read a data from csv file

>>> import pandas
>>> pandas.read_csv(‘concat_1.csv’)
0 a0 b0 c0 d0
1 a1 b1 c1 d1
2 a2 b2 c2 d2
3 a3 b3 c3 d3

We can save this data to a variable so that it’s much more useful

>>> df = pandas.read_csv(‘concat_1.csv’)
>>> df
0 a0 b0 c0 d0
1 a1 b1 c1 d1
2 a2 b2 c2 d2
3 a3 b3 c3 d3

To print first five entries

>>> print(df.head())
0 a0 b0 c0 d0
1 a1 b1 c1 d1
2 a2 b2 c2 d2
3 a3 b3 c3 d3

Now look at the type of df variable

>>> type(df)
<class ‘pandas.core.frame.DataFrame’>

Shape of object

>>> print(df.shape)
(4, 4)

Some more information like column header,there type and info

>>> print(df.columns)
Index([‘A’, ‘B’, ‘C’, ‘D’], dtype=’object’)
>>> print(df.dtypes)
A object
B object
C object
D object
dtype: object
>>> print(
<class ‘pandas.core.frame.DataFrame’>
RangeIndex: 4 entries, 0 to 3
Data columns (total 4 columns):
A 4 non-null object
B 4 non-null object
C 4 non-null object
D 4 non-null object
dtypes: object(4)
memory usage: 208.0+ bytes
Show your support

Clapping shows how much you appreciated Prashant Lakhera’s story.