title: Word cloud of keywords in Python
body: <p>I'm using Python to create a word cloud of keywords in a journal. The problem I have is that I don't want separate words in the keyword to be split but instead be considered together. I managed to do this by replacing a space character <code>' '</code> by <code>'_'</code>, but now the problem is that the final image I get of course has the underscore character. This is the code:</p>
  
  <pre><code>import numpy as np
  import pandas as pd
  from os import path
  from PIL import Image
  from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator
  import matplotlib.pyplot as plt
  
  # Load in the dataframe
  df = pd.read_csv("input/cmame_0.csv")
  l = df['Author Keywords'].str.split(';', expand=False).tolist()
  text = ';'.join([item for sublist in l if isinstance(sublist,list) for item in sublist])
  
  text = text.replace(" ", "_")
  
  stopwords = set(STOPWORDS)
  
  # Create and generate a word cloud image:
  wordcloud = WordCloud(stopwords=stopwords,
                        max_font_size=50,
                        max_words=100,
                        background_color="white").generate(text)
  
  # Display the generated image:
  plt.imshow(wordcloud, interpolation='bilinear')
  plt.axis("off")
  plt.show()
  </code></pre>
  
  <p>which produces</p>
  
  <p><a href="https://i.stack.imgur.com/VnjSs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VnjSs.png" alt="enter image description here"></a></p>
  
  <p>There's a regex expression I could use here but I can't seem to find the right regular expression.</p>