In [2]:
import pandas as pd

Create a Series Object from a Python List


In [2]:
ice_cream = ["Chocolate", "Vanilla", "Strawberry", "Rum Raisin"]
pd.Series(ice_cream)


Out[2]:
0     Chocolate
1       Vanilla
2    Strawberry
3    Rum Raisin
dtype: object

In [3]:
lottery = [7, 20, 9, 10, 17, 12]
pd.Series(lottery)


Out[3]:
0     7
1    20
2     9
3    10
4    17
5    12
dtype: int64

In [ ]:

Create A Series Object from a Dictionary


In [4]:
books = {"It" : "Stephen King", "The Collector" : "John Fowles", "A Game Of Thrones" : "George R. R. Martin", "Sugar Blues" : "William Dufty"}

pd.Series(books)


Out[4]:
A Game Of Thrones    George R. R. Martin
It                          Stephen King
Sugar Blues                William Dufty
The Collector                John Fowles
dtype: object

Intro to Attributes


In [6]:
b = pd.Series(books)
b


Out[6]:
A Game Of Thrones    George R. R. Martin
It                          Stephen King
Sugar Blues                William Dufty
The Collector                John Fowles
dtype: object

In [7]:
b.values


Out[7]:
array(['George R. R. Martin', 'Stephen King', 'William Dufty',
       'John Fowles'], dtype=object)

In [8]:
b.index


Out[8]:
Index(['A Game Of Thrones', 'It', 'Sugar Blues', 'The Collector'], dtype='object')

In [9]:
b.dtype


Out[9]:
dtype('O')

In [ ]:

Intro to Methods


In [12]:
prices = [2.99, 4.45, 1.36]
s = pd.Series(prices)
s


Out[12]:
0    2.99
1    4.45
2    1.36
dtype: float64

In [13]:
s.sum()


Out[13]:
8.8

In [14]:
s.product()


Out[14]:
18.095480000000006

In [16]:
s.mean()


Out[16]:
2.9333333333333336

In [17]:
s.min()


Out[17]:
1.3600000000000001

Parameters and Arguments


In [18]:
# Dificulty - Easy, Medium, Hard
# Volume - 1 through 10
# Subtitles - True / False

In [21]:
fruits = ["Apple", "Orange", "Grape", "Strawberry", "Mango"]
weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]

pd.Series(data=fruits, index=weekdays)


Out[21]:
Monday            Apple
Tuesday          Orange
Wednesday         Grape
Thursday     Strawberry
Friday            Mango
dtype: object

In [22]:
fruits = ["Apple", "Orange", "Grape", "Strawberry", "Mango", "Watermelon"]
weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Monday"]

pd.Series(data=fruits, index=weekdays)


Out[22]:
Monday            Apple
Tuesday          Orange
Wednesday         Grape
Thursday     Strawberry
Friday            Mango
Monday       Watermelon
dtype: object

Import Series from read_csv Method


In [6]:
pokemon = pd.read_csv("pokemon.csv", usecols=["Pokemon"], squeeze=True)
pokemon


Out[6]:
0       Bulbasaur
1         Ivysaur
2        Venusaur
3      Charmander
4      Charmeleon
5       Charizard
6        Squirtle
7       Wartortle
8       Blastoise
9        Caterpie
10        Metapod
11     Butterfree
12         Weedle
13         Kakuna
14       Beedrill
15         Pidgey
16      Pidgeotto
17        Pidgeot
18        Rattata
19       Raticate
20        Spearow
21         Fearow
22          Ekans
23          Arbok
24        Pikachu
25         Raichu
26      Sandshrew
27      Sandslash
28        Nidoran
29       Nidorina
          ...    
691     Clauncher
692     Clawitzer
693    Helioptile
694     Heliolisk
695        Tyrunt
696     Tyrantrum
697        Amaura
698       Aurorus
699       Sylveon
700      Hawlucha
701       Dedenne
702       Carbink
703         Goomy
704       Sliggoo
705        Goodra
706        Klefki
707      Phantump
708     Trevenant
709     Pumpkaboo
710     Gourgeist
711      Bergmite
712       Avalugg
713        Noibat
714       Noivern
715       Xerneas
716       Yveltal
717       Zygarde
718       Diancie
719         Hoopa
720     Volcanion
Name: Pokemon, Length: 721, dtype: object

In [8]:
pd.read_csv("google_stock_price.csv", squeeze=True)


Out[8]:
0        50.12
1        54.10
2        54.65
3        52.38
4        52.95
5        53.90
6        53.02
7        50.95
8        51.13
9        50.07
10       50.70
11       49.95
12       50.74
13       51.10
14       51.10
15       52.61
16       53.70
17       55.69
18       55.94
19       56.93
20       58.69
21       59.62
22       58.86
23       59.13
24       60.35
25       59.86
26       59.07
27       63.37
28       65.47
29       64.74
         ...  
2982    675.22
2983    668.26
2984    680.04
2985    684.11
2986    692.10
2987    699.21
2988    694.49
2989    697.77
2990    695.36
2991    705.63
2992    715.09
2993    720.64
2994    716.98
2995    720.95
2996    719.85
2997    733.78
2998    736.96
2999    741.19
3000    738.63
3001    742.74
3002    739.77
3003    738.42
3004    741.77
3005    745.91
3006    768.79
3007    772.88
3008    771.07
3009    773.18
3010    771.61
3011    782.22
Name: Stock Price, Length: 3012, dtype: float64

The .head() and .tail() Methods


In [10]:
pokemon = pd.read_csv("pokemon.csv", usecols=["Pokemon"], squeeze=True)
google = pd.read_csv("google_stock_price.csv", squeeze=True)

In [17]:
pokemon.head(9)


Out[17]:
0     Bulbasaur
1       Ivysaur
2      Venusaur
3    Charmander
4    Charmeleon
5     Charizard
6      Squirtle
7     Wartortle
8     Blastoise
Name: Pokemon, dtype: object

In [18]:
google.tail(10)


Out[18]:
3002    739.77
3003    738.42
3004    741.77
3005    745.91
3006    768.79
3007    772.88
3008    771.07
3009    773.18
3010    771.61
3011    782.22
Name: Stock Price, dtype: float64

More Series Attributes


In [3]:
pokemon = pd.read_csv("pokemon.csv", usecols=["Pokemon"], squeeze=True)
google = pd.read_csv("google_stock_price.csv", squeeze=True)

In [21]:
pokemon.is_unique


Out[21]:
True

In [22]:
google.is_unique


Out[22]:
False

In [23]:
pokemon.ndim


Out[23]:
1

In [24]:
pokemon.shape


Out[24]:
(721,)

The .sort_values() Method


In [4]:
pokemon = pd.read_csv("pokemon.csv", usecols=["Pokemon"], squeeze=True)
google = pd.read_csv("google_stock_price.csv", squeeze=True)

In [16]:
pokemon.sort_values(ascending=False).tail()


Out[16]:
680    Aegislash
616     Accelgor
358        Absol
62          Abra
459    Abomasnow
Name: Pokemon, dtype: object

In [17]:
pokemon.sort_values(ascending=True, kind="mergesort").head()


Out[17]:
459    Abomasnow
62          Abra
358        Absol
616     Accelgor
680    Aegislash
Name: Pokemon, dtype: object

The inplace Parameter


In [18]:
pokemon = pd.read_csv("pokemon.csv", usecols=["Pokemon"], squeeze=True)
google = pd.read_csv("google_stock_price.csv", squeeze=True)

In [19]:
google.head(3)


Out[19]:
0    50.12
1    54.10
2    54.65
Name: Stock Price, dtype: float64

In [21]:
google.sort_values().head(3)


Out[21]:
11    49.95
9     50.07
0     50.12
Name: Stock Price, dtype: float64

In [22]:
google = google.sort_values()

In [24]:
google.head(3)


Out[24]:
11    49.95
9     50.07
0     50.12
Name: Stock Price, dtype: float64

In [26]:
google.sort_values(ascending=False, inplace=True)

In [27]:
google.head(3)


Out[27]:
3011    782.22
2859    776.60
3009    773.18
Name: Stock Price, dtype: float64

In [ ]:


In [ ]:


In [ ]: