https://youtu.be/0UA49Ds1XXo?list=PLQVvvaa0QuDc-3szzjeP6N6b0aDrrKyL-
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
In [4]:
data_frame.set_index("Day");
print(data_frame);
print(data_frame.set_index("Day")); #this is the function!
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);
In [8]:
print(data_frame["Visitors"]);
print(data_frame.Visitors); #there is no difference
In [12]:
print(data_frame[["Bounce Rate", "Visitors"]]);
In [14]:
print(data_frame.Visitors.tolist());
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]);
In [22]:
data_frame_2 = pd.DataFrame(np_bounce_visitors_array);
print(data_frame_2);
In [ ]: