title: for if loop to categorize under condition
body: <p>I am pretty new to python and used to use R. For this matter, I would use as.factor and categorize based on the number.</p>
  
  <p>Earlier I was trying to use replace and .loc function in order to give a new category value in a new column according to the condition but it would run only to fail at what I wanted to do.</p>
  
  <p>Eventually I created the following, very simple function:</p>
  
  <pre><code>g['Category'] = ""
  
  for i in g['NumFloorsGroup']:
      if i == '0-9' or i == '10-19':
          g['Category'] = 'LowFl'
      elif i == '50~':
          g['Category'] = 'HighFl'
      else:
          g['Category'] = 'NormalFl'
  </code></pre>
  
  <p>When I run the function though, it only returns the 'LowFl' and doesn't correct the other parts. I feel like I am missing something.</p>
  
  <p>the data info is as follows:</p>
  
  <pre><code>&lt;class 'pandas.core.frame.DataFrame'&gt;
  Int64Index: 596 entries, 128 to 595
  Data columns (total 4 columns):
  YearBuilt         596 non-null int64
  NumFloorsGroup    596 non-null category
  Count             596 non-null int64
  Category          596 non-null object
  dtypes: category(1), int64(2), object(1)
  </code></pre>
  
  <p>Any comment will be helpful!</p>
  
  <pre><code>bins = [0, 10, 20, 30, 40, 50, np.inf]
  labels = ['0-9', '10-19', '20-29', '30-39', '40-49', '50~']
  copy = original_data.copy()
  copy['NumFloorsGroup'] = pd.cut(copy['NumFloors'], bins=bins, labels=labels, include_lowest=True)
  
  g = (copy.groupby(['YearBuilt', 'NumFloorsGroup'])['YearBuilt']
          .count()
          .reset_index(name="Count")
                   .sort_values(by='Count', ascending=False))
  </code></pre>
  
  <p>And the parts that only returns LowFl</p>
  
  <pre><code>g['Category'] = ""
  
  for i in g['NumFloorsGroup']:
      if i == '0-9' or i == '10-19':
          g['Category'] = 'LowFl'
      elif i == '50~':
          g['Category'] = 'HighFl'
      else:
          g['Category'] = 'NormalFl'
  </code></pre>
  
  <p>This returns All the Category as LowFl</p>
  
  <pre><code>    YearBuilt   NumFloorsGroup  Count   Category
  128 1920    0-9 90956   LowFl
  171 1930    0-9 76659   LowFl
  144 1925    0-9 70387   LowFl
  237 1950    0-9 47237   LowFl
  91  1910    0-9 46384   LowFl
  </code></pre>