In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

In [3]:
s = pd.Series([1,3,5,np.nan,6,8])
s


Out[3]:
0    1.0
1    3.0
2    5.0
3    NaN
4    6.0
5    8.0
dtype: float64

In [4]:
dates = pd.date_range('20130101',periods=6)

In [5]:
dates


Out[5]:
DatetimeIndex(['2013-01-01', '2013-01-02', '2013-01-03', '2013-01-04',
               '2013-01-05', '2013-01-06'],
              dtype='datetime64[ns]', freq='D')

In [6]:
df = pd.DataFrame(np.random.randn(6,4),index = dates,columns=list('ABCD'))
df


Out[6]:
A B C D
2013-01-01 -1.164873 0.008331 0.801343 -0.217401
2013-01-02 -1.567579 -1.793393 0.753424 -0.289366
2013-01-03 -0.733508 0.829952 2.265642 2.105826
2013-01-04 0.980079 -0.107410 1.225999 -0.554620
2013-01-05 -0.992219 1.327886 0.648874 0.227911
2013-01-06 0.529250 -0.085388 2.327908 -1.007254

In [11]:
df2 = pd.DataFrame({'A': 1.,
                    'B': pd.Timestamp('20130102'),
                    'C': pd.Series(1,index = list((range(4)))),
                    'D': np.array([3]*4),
                    'E': pd.Categorical(["surya","teja","bala","dileep"]),
                    'F': 'Foo'})
df2


Out[11]:
A B C D E F
0 1.0 2013-01-02 1 3 surya Foo
1 1.0 2013-01-02 1 3 teja Foo
2 1.0 2013-01-02 1 3 bala Foo
3 1.0 2013-01-02 1 3 dileep Foo

In [21]:
df2.tail(2)


Out[21]:
A B C D E F
2 1.0 2013-01-02 1 3 bala Foo
3 1.0 2013-01-02 1 3 dileep Foo

In [26]:
df2.dtypes


Out[26]:
A           float64
B    datetime64[ns]
C             int64
D             int64
E          category
F            object
dtype: object

In [27]:
df2.


  File "<ipython-input-27-e8d0e54abc86>", line 1
    df2.<TAB>
        ^
SyntaxError: invalid syntax

In [29]:
df.index


Out[29]:
DatetimeIndex(['2013-01-01', '2013-01-02', '2013-01-03', '2013-01-04',
               '2013-01-05', '2013-01-06'],
              dtype='datetime64[ns]', freq='D')

In [31]:
df2.columns


Out[31]:
Index(['A', 'B', 'C', 'D', 'E', 'F'], dtype='object')

In [32]:
df2.values


Out[32]:
array([[1.0, Timestamp('2013-01-02 00:00:00'), 1, 3, 'surya', 'Foo'],
       [1.0, Timestamp('2013-01-02 00:00:00'), 1, 3, 'teja', 'Foo'],
       [1.0, Timestamp('2013-01-02 00:00:00'), 1, 3, 'bala', 'Foo'],
       [1.0, Timestamp('2013-01-02 00:00:00'), 1, 3, 'dileep', 'Foo']], dtype=object)

In [34]:
df.describe()
df2.describe()


Out[34]:
A C D
count 4.0 4.0 4.0
mean 1.0 1.0 3.0
std 0.0 0.0 0.0
min 1.0 1.0 3.0
25% 1.0 1.0 3.0
50% 1.0 1.0 3.0
75% 1.0 1.0 3.0
max 1.0 1.0 3.0

In [36]:
#Transposing the data
print(df)
print(df.T)


                   A         B         C         D
2013-01-01 -1.164873  0.008331  0.801343 -0.217401
2013-01-02 -1.567579 -1.793393  0.753424 -0.289366
2013-01-03 -0.733508  0.829952  2.265642  2.105826
2013-01-04  0.980079 -0.107410  1.225999 -0.554620
2013-01-05 -0.992219  1.327886  0.648874  0.227911
2013-01-06  0.529250 -0.085388  2.327908 -1.007254
   2013-01-01  2013-01-02  2013-01-03  2013-01-04  2013-01-05  2013-01-06
A   -1.164873   -1.567579   -0.733508    0.980079   -0.992219    0.529250
B    0.008331   -1.793393    0.829952   -0.107410    1.327886   -0.085388
C    0.801343    0.753424    2.265642    1.225999    0.648874    2.327908
D   -0.217401   -0.289366    2.105826   -0.554620    0.227911   -1.007254

In [42]:
print(df)
df.sort_index(axis=1,ascending=True)


                   A         B         C         D
2013-01-01 -1.164873  0.008331  0.801343 -0.217401
2013-01-02 -1.567579 -1.793393  0.753424 -0.289366
2013-01-03 -0.733508  0.829952  2.265642  2.105826
2013-01-04  0.980079 -0.107410  1.225999 -0.554620
2013-01-05 -0.992219  1.327886  0.648874  0.227911
2013-01-06  0.529250 -0.085388  2.327908 -1.007254
Out[42]:
A B C D
2013-01-01 -1.164873 0.008331 0.801343 -0.217401
2013-01-02 -1.567579 -1.793393 0.753424 -0.289366
2013-01-03 -0.733508 0.829952 2.265642 2.105826
2013-01-04 0.980079 -0.107410 1.225999 -0.554620
2013-01-05 -0.992219 1.327886 0.648874 0.227911
2013-01-06 0.529250 -0.085388 2.327908 -1.007254

In [43]:
df.sort_values(by='B')


Out[43]:
A B C D
2013-01-02 -1.567579 -1.793393 0.753424 -0.289366
2013-01-04 0.980079 -0.107410 1.225999 -0.554620
2013-01-06 0.529250 -0.085388 2.327908 -1.007254
2013-01-01 -1.164873 0.008331 0.801343 -0.217401
2013-01-03 -0.733508 0.829952 2.265642 2.105826
2013-01-05 -0.992219 1.327886 0.648874 0.227911

In [44]:
df.A


Out[44]:
2013-01-01   -1.164873
2013-01-02   -1.567579
2013-01-03   -0.733508
2013-01-04    0.980079
2013-01-05   -0.992219
2013-01-06    0.529250
Freq: D, Name: A, dtype: float64

In [50]:
df[0:3]


Out[50]:
A B C D
2013-01-01 -1.164873 0.008331 0.801343 -0.217401
2013-01-02 -1.567579 -1.793393 0.753424 -0.289366
2013-01-03 -0.733508 0.829952 2.265642 2.105826