title: More efficient way to replace special chars with their unicode name in pandas df
body: <p>I have a large pandas dataframe and would like to perform a thorough text cleaning on it. For this, I have crafted the below code that evaluates if a character is either an emoji, number, Roman number, or a currency symbol, and replaces these with their unidode name from the <code>unicodedata</code> package.</p>
  <p>The code uses a double for loop though and I believe there must be far more efficient solutions than that but I haven't managed to figure out yet how I could implement it in a vectorized manner.</p>
  <p>My current code is as follows:</p>
  <pre><code>from unicodedata import name as unicodename 
  
  def clean_text(text):
      for item in text:
          for char in item: 
              # Simple space
              if char == ' ':
                  newtext += char 
              # Letters
              elif category(char)[0] == 'L':
                  newtext += char
              # Other symbols: emojis
              elif category(char) == 'So':
                  newtext += f&quot; {unicodename(char)} &quot;
              # Decimal numbers 
              elif category(char) == 'Nd':
                  newtext += f&quot; {unicodename(char).replace('DIGIT ', '').lower()} &quot;
              # Letterlike numbers e.g. Roman numerals 
              elif category(char) == 'Nl':
                  newtext += f&quot; {unicodename(char)} &quot;
              # Currency symbols
              elif category(char) == 'Sc':
                  newtext += f&quot; {unicodename(char).replace(' SIGN', '').lower()} &quot;
              # Punctuation, invisibles (separator, control chars), maths symbols...
              else:
                  newtext += &quot; &quot;
  </code></pre>
  <p>At the moment I am using this function on my dataframe with an apply:</p>
  <pre><code>df['Texts'] = df['Texts'].apply(lambda x: clean_text(x))
  </code></pre>
  <p>Sample data:</p>
  <pre><code>l = [
      &quot;thumbs ups should be replaced: &quot;,
      &quot;hearts also should be replaced:  ❤️️❤️️❤️️❤️️&quot;,
      &quot;also other emojis: ☺️☺️&quot;,
      &quot;numbers and digits should also go: 40/40&quot;,
      &quot;Ⅰ, Ⅱ, Ⅲ these are roman numerals, change 'em&quot;
  ]
  df = pd.DataFrame(l, columns=['Texts'])
  </code></pre>