df = pd.read_csv('sample.csv', usecols=['Z'])
df['Obs'] = 1
gp = df.groupby('Z')
df2 = np.ceil(gp.count() * stratfraction)
stratsample = []
for i, key in enumerate(gp.groups):
    FirstFracEntries = gp.groups[key][0:int(df2['Obs'][i])]
stratsample.extend(FirstFracEntries)
stratsample.sort
RowsToSkip = set(df.index.values).difference(stratsample)
df3 = df = pd.read_csv('sample.csv', skiprows=RowsToSkip)
Sampling groups in Pandas