title: Is there a way to use vectorization in place of this nested for loop?
body: <p>I have this current (working as designed) nested for-loop that grabs some data of interest and creates a pandas dataframe from it. In an effort to cut down on runtime, I have been trying to figure out if vectorization could be a good replacement for the nested for-loop. Is there any way to vectorize these loops?</p>
  <pre><code>for i, row in enumerate(ldamodel[corpus]):
          row = sorted(row, key=lambda x: (x[1]), reverse=True)
          # Get the Dominant topic, % Contribution and Keywords for each document
          for j, (topic_num, prop_topic) in enumerate(row):
              if j == 0:  # Pull dominant topic
                  wp = ldamodel.show_topic(topic_num)
                  topic_keywords = &quot;, &quot;.join([word for word, prop in wp])
                  sent_topics_df = sent_topics_df.append(pd.Series([int(topic_num), ldamodel.get_document_topics(corpus[i]), topic_keywords]), ignore_index=True)
              else:
                  break
  </code></pre>