title: How to quickly group multiple features of data from a dataframe using pandas
body: <p>Let's say this is my original data:</p>
  <pre><code>data = {'library_id': ['A123', 'A456','B123', 'A123', 'A123', 'B123', 'A456'],
       'school': ['A1','A', 'B', 'A', 'A2', 'B', 'A'],
       'charge ($)': [5.0, 10.0, 3.0, 2.5, 1.0, 4.0, 2.5], 
       'check_in_month': [12, 3, 4, 5, 4, 9, 5]}
  library =pd.DataFrame(data)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/2EXWa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2EXWa.png" alt="enter image description here" /></a></p>
  <p>I am trying to get this outcome:</p>
  <p><a href="https://i.stack.imgur.com/VrB3C.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VrB3C.png" alt="enter image description here" /></a></p>
  <p>And this is my code to get the outcome:</p>
  <pre><code>df = pd.DataFrame(library.library_id.value_counts())
  
  school_list = []
  for i in df.index:
      school_list.append(library[library.library_id == i].school.unique())
  df['school'] = school_list
  df  
  </code></pre>
  <p>My question is how I can avoid using lists (i.e. school_list = []) to get the same outcome. Because when I have large data, using lists to append data to a data frame is super time-consuming. Is there any other faster way?</p>