Pandas Builtin Data Visuali

In [14]:
import numpy as np
import pandas as pd
import seaborn as sns

%matplotlib inline
In [15]:
# Get data from csv files [df1,df2,df3]

df1 = pd.read_csv('df1', index_col=0)
df2 = pd.read_csv('df2')
df3 = pd.read_csv('df3')
In [16]:
df1.head()
Out[16]:
A B C D
2000-01-01 1.339091 -0.163643 -0.646443 1.041233
2000-01-02 -0.774984 0.137034 -0.882716 -2.253382
2000-01-03 -0.921037 -0.482943 -0.417100 0.478638
2000-01-04 -1.738808 -0.072973 0.056517 0.015085
2000-01-05 -0.905980 1.778576 0.381918 0.291436
In [31]:
df2
Out[31]:
a b c d
0 0.039762 0.218517 0.103423 0.957904
1 0.937288 0.041567 0.899125 0.977680
2 0.780504 0.008948 0.557808 0.797510
3 0.672717 0.247870 0.264071 0.444358
4 0.053829 0.520124 0.552264 0.190008
5 0.286043 0.593465 0.907307 0.637898
6 0.430436 0.166230 0.469383 0.497701
7 0.312296 0.502823 0.806609 0.850519
8 0.187765 0.997075 0.895955 0.530390
9 0.908162 0.232726 0.414138 0.432007
In [18]:
df3.head()
Out[18]:
a b c d
0 0.336272 0.325011 0.001020 0.401402
1 0.980265 0.831835 0.772288 0.076485
2 0.480387 0.686839 0.000575 0.746758
3 0.502106 0.305142 0.768608 0.654685
4 0.856602 0.171448 0.157971 0.321231

Histograms

In [53]:
df1['A'].hist()
Out[53]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a1d4da3c8>
In [54]:
df1['A'].plot.hist()
Out[54]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a1d55eba8>

Area Plot

In [29]:
df2.plot.area(alpha=0.6)
Out[29]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a1bd5b470>

Bar plot - Stacked

In [32]:
df2.plot.bar(stacked=True)
Out[32]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a1bfd6c50>
In [33]:
df1.head()
Out[33]:
A B C D
2000-01-01 1.339091 -0.163643 -0.646443 1.041233
2000-01-02 -0.774984 0.137034 -0.882716 -2.253382
2000-01-03 -0.921037 -0.482943 -0.417100 0.478638
2000-01-04 -1.738808 -0.072973 0.056517 0.015085
2000-01-05 -0.905980 1.778576 0.381918 0.291436

Line Plot

In [36]:
df1.plot.line(x=df1.index,y='B', figsize=(12,3))
Out[36]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a1c1f9860>

Scatter Plot

In [39]:
df1.plot.scatter(x='A',y='B',c='C',cmap='coolwarm')
Out[39]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a1cc21940>

Box Plot

In [40]:
df2.plot.box()
Out[40]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a1ccaac88>

Hexagonal plot

   for bivariate data
In [47]:
df = pd.DataFrame(np.random.randn(1000,2),columns=['a','b'])

df.plot.hexbin(x='a',y='b',gridsize=25)
Out[47]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a1c0e5f98>

Kernel Density Plot

In [51]:
df2.plot.kde()
# df2.plot.density()
Out[51]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a1d2b8c88>