Help with replacing values in a data frame I'm a data science student at Mills and working on CoCalc. I am working with the 'wine quality' set that can be found on the UCI website for my final project. I'm just working with the white wine portion. The target is the quality of the wine, rated from 1-10. I would like to change the values in the column 'quality' such that if the value is from 1-4, it is replaced with 'low', if the value is from 5-6, the value is replaced with 'medium', and if the value is 8-10, it is replaced with 'high'. My code is as such:
#Read in data
white = pd.read_csv('Wine_data.csv')

#Rename columns to exlude the u
columns = ['fixed acidity', 'volatile acidity', 'citric acid','residual sugar', 'chlorides', 'free sulfur dioxide','total sulfur dioxide', 'density', 'pH', 'sulphates', 'alcohol', 'quality']
white.columns = columns

quality = np.array(white['quality'])

for i in range(len(quality)):
    if quality[i] in [1,2,3,4]:
        quality[i] = 'low'
    elif quality[i] in [5,6,7]:
        quality[i] = 'med'
    else:
        quality[i] = 'high'

However, I am getting this error:
Error in lines 13-19
Traceback (most recent call last):
  File &quot;/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py&quot;, line 1013, in execute
    exec compile(block+'\n', '', 'single') in namespace, locals
  File &quot;&quot;, line 5, in &lt;module&gt;
ValueError: invalid literal for long() with base 10: 'med'

Here is a link to my code.
Help this nOOb please.
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'