This notebook is part of the IPython NB Example; the content is available on GitHub.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

< IPynb Example 1 | Contents | IPynb Example 3 >

IPynb Example 2

Purpose: The purpose of this workbook is to help you get comfortable with the topics below.

Recomended Usage

  • Run each of the cells (Shift+Enter) and edit them as necessary to solidify your understanding
  • Do any of the exercises that are relevant to helping you understand the material

Topics Covered

  • Test Display Pandas
  • Test Display Seaborn

Introduction

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

In [2]:
import pandas as pd

import numpy as np  # just to show pandas compatability with np
import seaborn as sns  # just for getting some sample datasets

Test Display Pandas

In [3]:
# Series with cusom indicies
s4 = pd.Series([0, 1, 2, 3], index=['a', 'b', 'c', 'd'])
s4
Out[3]:
a    0
b    1
c    2
d    3
dtype: int64
In [4]:
# Series from a dictionary
dict = {'a': 0,
        'b': [1, 2, 3],
        'c': 2}

s5 = pd.Series(dict)
s5
Out[4]:
a            0
b    [1, 2, 3]
c            2
dtype: object
In [5]:
# DataFrame from Python list
df1 = pd.DataFrame([0, 10, 20, 30, 40])
df1
Out[5]:
0
0 0
1 10
2 20
3 30
4 40
In [6]:
# Dataframe with different types and lengths
df2 = pd.DataFrame([3, ['a', 'b', 'c']])
df2
Out[6]:
0
0 3
1 [a, b, c]
In [7]:
# Explicitly name the columns
data = [['a', 12], ['b', 20], ['c', 40], ['d', 33], ['e', 88]]

df3 = pd.DataFrame(data, columns=['letters', 'numbers'], dtype=float)
df3
Out[7]:
letters numbers
0 a 12.0
1 b 20.0
2 c 40.0
3 d 33.0
4 e 88.0

Test Display Seaborn

In [8]:
diamonds_df = sns.load_dataset('diamonds')
In [9]:
# Checkout the beginning of the data
diamonds_df.head()
Out[9]:
carat cut color clarity depth table price x y z
0 0.23 Ideal E SI2 61.5 55.0 326 3.95 3.98 2.43
1 0.21 Premium E SI1 59.8 61.0 326 3.89 3.84 2.31
2 0.23 Good E VS1 56.9 65.0 327 4.05 4.07 2.31
3 0.29 Premium I VS2 62.4 58.0 334 4.20 4.23 2.63
4 0.31 Good J SI2 63.3 58.0 335 4.34 4.35 2.75
In [10]:
# Checkout the end of the data
diamonds_df.tail()
Out[10]:
carat cut color clarity depth table price x y z
53935 0.72 Ideal D SI1 60.8 57.0 2757 5.75 5.76 3.50
53936 0.72 Good D SI1 63.1 55.0 2757 5.69 5.75 3.61
53937 0.70 Very Good D SI1 62.8 60.0 2757 5.66 5.68 3.56
53938 0.86 Premium H SI2 61.0 58.0 2757 6.15 6.12 3.74
53939 0.75 Ideal D SI2 62.2 55.0 2757 5.83 5.87 3.64
In [12]:
sns.catplot(x="color", y="price", kind="boxen",
            data=diamonds_df.sort_values("color"));