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

from matplotlib import style;
style.use("ggplot");

In [2]:
web_stats = {"Day":[1, 2, 3, 4, 5, 6],
            "Visitors":[11, 12, 13, 14, 15, 16],
            "Bounce Rate":[21, 22, 23, 24, 25, 26]};

data_frame = pd.DataFrame(web_stats);

In [3]:
print(data_frame);
print(data_frame.head()); #feel the difference!

print(data_frame.tail(2)); # able for head too


   Bounce Rate  Day  Visitors
0           21    1        11
1           22    2        12
2           23    3        13
3           24    4        14
4           25    5        15
5           26    6        16
   Bounce Rate  Day  Visitors
0           21    1        11
1           22    2        12
2           23    3        13
3           24    4        14
4           25    5        15
   Bounce Rate  Day  Visitors
4           25    5        15
5           26    6        16

In [4]:
data_frame.set_index("Day");
print(data_frame);

print(data_frame.set_index("Day")); #this is the function!


   Bounce Rate  Day  Visitors
0           21    1        11
1           22    2        12
2           23    3        13
3           24    4        14
4           25    5        15
5           26    6        16
     Bounce Rate  Visitors
Day                       
1             21        11
2             22        12
3             23        13
4             24        14
5             25        15
6             26        16

In [5]:
data_frame = pd.DataFrame(web_stats); #refresh

data_frame.set_index("Day", inplace=True); #we cannot call this twice
print(data_frame);

data_frame = pd.DataFrame(web_stats);


     Bounce Rate  Visitors
Day                       
1             21        11
2             22        12
3             23        13
4             24        14
5             25        15
6             26        16

In [8]:
print(data_frame["Visitors"]); 
print(data_frame.Visitors); #there is no difference


0    11
1    12
2    13
3    14
4    15
5    16
Name: Visitors, dtype: int64
0    11
1    12
2    13
3    14
4    15
5    16
Name: Visitors, dtype: int64

In [12]:
print(data_frame[["Bounce Rate", "Visitors"]]);


   Bounce Rate  Visitors
0           21        11
1           22        12
2           23        13
3           24        14
4           25        15
5           26        16

In [14]:
print(data_frame.Visitors.tolist());


[11, 12, 13, 14, 15, 16]

In [20]:
import numpy as np;

np_bounce_visitors_array = np.array(data_frame[["Bounce Rate", "Visitors"]]);
print(np.array(data_frame[["Bounce Rate", "Visitors"]]));
print(np_bounce_visitors_array[1][0]);


[[21 11]
 [22 12]
 [23 13]
 [24 14]
 [25 15]
 [26 16]]
22

In [22]:
data_frame_2 = pd.DataFrame(np_bounce_visitors_array);
print(data_frame_2);


    0   1
0  21  11
1  22  12
2  23  13
3  24  14
4  25  15
5  26  16

In [ ]: