In [23]:
import pandas as pd

In [24]:
# TODO: Load up the dataset
# Ensuring you set the appropriate header column names
df = pd.read_csv('Datasets/servo.data')
columns = ['motor', 'screw', 'pgain', 'vgain', 'class']
df.columns = columns
df.head(5)


Out[24]:
motor screw pgain vgain class
0 B D 6 5 0.506252
1 D D 4 3 0.356251
2 B A 3 2 5.500033
3 D B 6 5 0.356251
4 E C 4 3 0.806255

In [25]:
# TODO: Create a slice that contains all entries
# having a vgain equal to 5. Then print the 
# length of (# of samples in) that slice:
eq5 = df[df.vgain ==5]
len(eq5)


Out[25]:
22

In [30]:
# TODO: Create a slice that contains all entries
# having a motor equal to E and screw equal
# to E. Then print the length of (# of
# samples in) that slice:
eqE = df[(df.motor == 'E') & (df.screw == 'E')]
eqE


Out[30]:
motor screw pgain vgain class
34 E E 3 2 1.100000
85 E E 4 3 0.843755
131 E E 6 5 0.281251
139 E E 4 2 0.506252
150 E E 3 1 0.700001

In [32]:
df_servo = df

df_servo[(df_servo.motor == 'E') & (df_servo.screw == 'E')]


Out[32]:
motor screw pgain vgain class
34 E E 3 2 1.100000
85 E E 4 3 0.843755
131 E E 6 5 0.281251
139 E E 4 2 0.506252
150 E E 3 1 0.700001

In [19]:
# TODO: Create a slice that contains all entries
# having a pgain equal to 4. Use one of the
# various methods of finding the mean vgain
# value for the samples in that slice. Once
# you've found it, print it:
eq4 = df[df.pgain == 4]
eq4.vgain.mean()


Out[19]:
2.0606060606060606

In [13]:
# TODO: (Bonus) See what happens when you run
# the .dtypes method on your dataframe!
df.dtypes


Out[13]:
motor     object
screw     object
pgain      int64
vgain      int64
class    float64
dtype: object