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]:
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]:
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]:
In [32]:
df_servo = df
df_servo[(df_servo.motor == 'E') & (df_servo.screw == 'E')]
Out[32]:
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]:
In [13]:
# TODO: (Bonus) See what happens when you run
# the .dtypes method on your dataframe!
df.dtypes
Out[13]: