Help with replacing values in a data frame
Assuming that the data is small enough that efficiency is not an issue, I would use the Pandas data frame and do something like:

white['quality_code'] = 'high'
white.loc[quality &lt; 5, 'quality_code'] = 'low'
white.loc[(quality &gt; 4) &amp; (quality &lt; 8) , 'quality_code'] = 'med'