title: Label based indexing Pandas (.loc)
body: <p>I have recently been made aware of the dangers of chained assignment, and I am trying to use the proper method of indexing in pandas using loc[rowindex, colindex]. I am working with mixed data types (mix within the same series of np.float64 and list and string) - this is unavoidable. I have an integer index</p>
  
  <p>I am running the following loop through a data frame</p>
  
  <pre><code>Count = 0
  for row in DF.index:
  print row
      if '/' in str(DF.order_no[row]) and '/' not in str(DF.buyer[row]) and '/' not in    str(DF.buyer[row])\
      and '/' not in str(DF.smv[row]) and '/' not in str(DF.item[row]):
          DF.loc[row, 'order_no'] = str(DF.loc[row, 'order_no']).split('/')
          Count +=1
  </code></pre>
  
  <p>Count    </p>
  
  <p>Which returns the error:</p>
  
  <pre><code> TypeError: object of type 'int' has no len()
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <p>Within that loop I can do:</p>
  
  <pre><code>print DF.loc[row, 'order_no']
  </code></pre>
  
  <p>and</p>
  
  <pre><code>print DF.loc[row, 'order_no'] == str(DF.loc[row, order_no]).split('/')
  </code></pre>
  
  <p>but not</p>
  
  <pre><code>DF.loc[row, 'order_no'] = str(DF.loc[row, order_no]).split('/')
  </code></pre>
  
  <p>Using the print statement I see that it gets stuck on row 3, yet:</p>
  
  <pre><code>DF.loc[3, 'order_no']
  </code></pre>
  
  <p>works just fine. </p>
  
  <p>Help apprecitated.</p>
  
  <p>EDIT</p>
  
  <p>A workaround is the following:</p>
  
  <pre><code>Count = 0
  Vals = []
  Ind = []
  for row in DF.index:
      if '/' in str(DF.order_no[row]) and '/' not in str(DF.buyer[row]) and '/' not in str(DF.buyer[row])\
      and '/' not in str(DF.smv[row]) and '/' not in str(DF.item[row]):
          Vals.append(DF.order_no[row].split('/'))
          Ind.append(row)
          Count +=1
  
  DF.loc[Ind, 'order_no'] = Vals    
  </code></pre>
  
  <p>In other words I can create a list of the values to be modified and then change them using .loc. This works fine which leads me to believge that the issue is not with the values I am tryng to assign, and with the assignment process itself.</p>
  
  <p>Here is an example of the type of data I am working on: The code fails on row 3 and 9 as far as i can tell. Sorry its in csv format, but this is how I am reading it into pandas.</p>
  
  <p><a href="https://www.dropbox.com/s/zuy8pj15nlhmcfb/EG2.csv" rel="nofollow">https://www.dropbox.com/s/zuy8pj15nlhmcfb/EG2.csv</a></p>
  
  <p>Using that data if the following is done:</p>
  
  <pre><code>EG = pd.reas_csv('EG.csv')
  EG.loc[3, 'order_no'] = str(EG.loc[3, 'order_no']).split('/')
  </code></pre>
  
  <p>Fails with the error</p>
  
  <p><code>object of type 'int' has no len()</code></p>
  
  <p>But</p>
  
  <pre><code>EG['order_no'][3] = str(EG.loc[3, 'order_no']).split('/')
  </code></pre>
  
  <p>works fine, but this is the type of chain assignment I am trying to avoid as it was giving me issues elsewhere.</p>
  
  <p>which is why I thought this was just a syntax error.</p>
  
  <p>Sorry for this now unweildy question</p>