title: Python: Pandas Series - Why use loc?
body: <p>Why do we use 'loc' for pandas dataframes? it seems the following code with or without using loc both compile anr run at a simulular speed</p>
  
  <pre><code>%timeit df_user1 = df.loc[df.user_id=='5561']
  
  100 loops, best of 3: 11.9 ms per loop
  </code></pre>
  
  <p>or</p>
  
  <pre><code>%timeit df_user1_noloc = df[df.user_id=='5561']
  
  100 loops, best of 3: 12 ms per loop
  </code></pre>
  
  <p>So why use loc?</p>
  
  <p><strong>Edit:</strong> This has been flagged as a duplicate question. But although <a href="https://stackoverflow.com/questions/31593201/pandas-iloc-vs-ix-vs-loc-explanation/31593712#31593712">pandas iloc vs ix vs loc explanation?</a> does mention that *</p>
  
  <blockquote>
    <p>you can do column retrieval just by using the data frame's
    <strong>getitem</strong>:</p>
  </blockquote>
  
  <p>*</p>
  
  <pre><code>df['time']    # equivalent to df.loc[:, 'time']
  </code></pre>
  
  <p>it does not say why we use loc, although it does explain lots of features of loc, my specific question is 'why not just omit loc altogether'? for which i have accepted a very detailed answer below.</p>
  
  <p>Also that other post the answer (which i do not think is an answer) is very hidden in the discussion and any person searching for what i was looking for would find it hard to locate the information and would be much better served by the answer provided to my question.</p>