title: Unable to set list of lists as series onto dataframe column
body: <p>I have a large dataframe with many records. Based on the event (one of my columns) I extract it as a list and manually do list slicing to simulate sliding window of arbitrary size. However, while it applied to first group of my dataframe, it fails to work for the other groups in my dataframe, only giving NaN values. I printed out the values before I try to use .loc to set the series onto my dataframe and the values exist.</p>
  <p>1st iteration:</p>
  <pre><code>        timestamp   event   String pattern
      0   2021-12-18 18:20:25+08:00   w   w
      1   2021-12-18 18:20:27+08:00   w   ww
      2   2021-12-18 18:20:29+08:00   w   www
      3   2021-12-18 18:20:31+08:00   w   wwww
      4   2021-12-18 18:20:33+08:00   w   wwwww
      ... ... ... ...
      1131    2021-12-18 18:58:07+08:00   w   wwwwwwwwwwwwwwwwwwwwwwwwwwwwww
      1132    2021-12-18 18:58:09+08:00   w   wwwwwwwwwwwwwwwwwwwwwwwwwwwwww
      1133    2021-12-18 18:58:11+08:00   w   wwwwwwwwwwwwwwwwwwwwwwwwwwwwww
      1134    2021-12-18 18:58:13+08:00   w   wwwwwwwwwwwwwwwwwwwwwwwwwwwwww
      1135    2021-12-18 18:58:15+08:00   w   wwwwwwwwwwwwwwwwwwwwwwwwwwwwww
  </code></pre>
  <p>2nd iteration:</p>
  <pre><code>    timestamp   event   String pattern
  1136    2021-12-19 07:20:43+08:00   r   NaN
  1137    2021-12-19 07:20:45+08:00   w   NaN
  1138    2021-12-19 07:20:47+08:00   w   NaN
  1139    2021-12-19 07:20:49+08:00   w   NaN
  1140    2021-12-19 07:20:51+08:00   w   NaN
  ... ... ... ...
  1781    2021-12-19 07:42:13+08:00   w   NaN
  1782    2021-12-19 07:42:15+08:00   w   NaN
  1783    2021-12-19 07:42:17+08:00   w   NaN
  1784    2021-12-19 07:42:19+08:00   w   NaN
  1785    2021-12-19 07:42:21+08:00   w   NaN
  </code></pre>
  <p>code:</p>
  <pre><code>unique_val = merged.timeframe.unique()
  
  for val in unique_val:
      merged_filtered = merged[merged['timeframe']==val]
      merged_filtered.loc[:, 'String pattern'] = &quot;&quot;
  
      shift = 30
  
      events = merged_filtered.event.tolist()
      values = []
      
      #print(events)
      
      for i in range(len(events)):
          #print(str(i))
          if i &lt; shift:
              values.append(events[:i+1])
          else:
              values.append(events[i-shift+1:i+1])
      
      
      #print(values)       
      merged_filtered.loc[:, 'String pattern'] = pd.Series(values).str.join('')
      display(merged_filtered[['timestamp', 'event', 'String pattern']])
  </code></pre>
  <p>The above is the code I am using. I get the unique groups (timeframes) in the dataframe, filter it out, and apply the sliding window to each group individually by using tolist() and slicing the list indices based on shift, the supposed window size (inclusive of current record)</p>
  <p>merged looks like the following:</p>
  <pre><code>    timeframe   timestamp   event   confidence  String pattern
  0   2021-12-18 18:21:25 +0800 to 2021-12-18 18:54:...   2021-12-18 18:20:25+08:00   w   2.0 w
  1   2021-12-18 18:21:25 +0800 to 2021-12-18 18:54:...   2021-12-18 18:20:27+08:00   w   2.0 ww
  2   2021-12-18 18:21:25 +0800 to 2021-12-18 18:54:...   2021-12-18 18:20:29+08:00   w   2.0 www
  3   2021-12-18 18:21:25 +0800 to 2021-12-18 18:54:...   2021-12-18 18:20:31+08:00   w   2.0 wwww
  4   2021-12-18 18:21:25 +0800 to 2021-12-18 18:54:...   2021-12-18 18:20:33+08:00   w   2.0 wwwww
  ... ... ... ... ... ...
  1131    2021-12-18 18:21:25 +0800 to 2021-12-18 18:54:...   2021-12-18 18:58:07+08:00   w   2.0 wwwwwwwwwwwwwwwwwwwwwwwwwwwwww
  1132    2021-12-18 18:21:25 +0800 to 2021-12-18 18:54:...   2021-12-18 18:58:09+08:00   w   2.0 wwwwwwwwwwwwwwwwwwwwwwwwwwwwww
  1133    2021-12-18 18:21:25 +0800 to 2021-12-18 18:54:...   2021-12-18 18:58:11+08:00   w   2.0 wwwwwwwwwwwwwwwwwwwwwwwwwwwwww
  1134    2021-12-18 18:21:25 +0800 to 2021-12-18 18:54:...   2021-12-18 18:58:13+08:00   w   2.0 wwwwwwwwwwwwwwwwwwwwwwwwwwwwww
  1135    2021-12-18 18:21:25 +0800 to 2021-12-18 18:54:...   2021-12-18 18:58:15+08:00   w   2.0 wwwwwwwwwwwwwwwwwwwwwwwwwwwwww
  </code></pre>