title: Did not quite understand what pandas `itertuples` is doing in the following code
body: <p>I was working on the <a href="https://grouplens.org/datasets/movielens/100k/" rel="nofollow noreferrer">MovieLens Dataset</a> for recommendation-engine example. I see that we can create a user-item matrix to calculate the similarity between them where we have the the users as index (or row number) and item (movies) as columns and the ratings on each movie by each user as the data in the matrix. I believe that is what the following code is doing and it looks powerful however, it  is not clear to me how it is actually working. Is there any other method we can use than itertuples (simple pivot or transpose? Any advantage or disadvantage?)  </p>
  
  <pre><code>import pandas as pd
  import numpy as np
  
  r_cols = ['user_id', 'movie_id', 'rating', 'unix_timestamp']
  ratings = pd.read_csv('ml-100k/u.data', sep='\t', 
  names=r_cols,encoding='latin-1')
  n_users = ratings.user_id.unique().shape[0]
  n_items = ratings.movie_id.unique().shape[0]
  
  data_matrix = np.zeros((n_users, n_items))
  for line in ratings.itertuples():
      data_matrix[line[1]-1, line[2]-1] = line[3]
  </code></pre>