title: Error operating data with pandas (in case of missing data)
body: <p>I have the DataFrame 'indata2'. The following code allows me to add an 'Indicator' column that groups my data based on Indata2['Label'].</p>
  <pre><code>import pandas as pd
  import numpy as np
  
  indata2 = [[2,  'SIS X+',      9.65,    'Q'],
            [2,   'SIS X-',      5.32,    'Q'],
            [2,   'SIS Y+',      8.24,    'Q'],
            [2,   'SIS Y-',      3.27,    'Q'],
            [2,   'SIS',        3.40, 'Q'],
            [2,   'C. VIV',      0.23,    'L'],
            [2,   'SOBRE P',  0.38,   'SD'],
            [2,   'SOBRE P',  0.19,   'SD'],
  #          [2,  'VIEN X+',  7.36,   'W'],
  #          [2,  'VIEN X-',  23.09,  'W'],
  #          [2,  'VIEN Y+',  6.66,   'W'],
  #          [2,  'VIEN Y-',  2.68,   'W'],
            [4,   'SIS X+',      14.41,   'Q'],
            [4,   'SIS X-',      12.23,   'Q'],
            [4,   'SIS Y+',      10.00,   'Q'],
            [4,   'SIS Y-',      11.00,   'Q'],
            [4,   'C. VIV',      0.38,    'L'],
            [4,   'C. VIV',      0.34,    'L'],
            [4,   'C. VIV',      0.13,    'L'],
            [4,   'SOBRE P',  0.62,   'SD']]
  #          [4,  'VIEN X+',  29.21,  'W'],
  #          [4,  'VIEN X-',  8.70,   'W'],
  #          [4,  'VIEN Y-',  7.46,   'W'],
  #          [4,  'VIEN Y+',  11.62,  'W'],
  #          [4,  'VIEN',      9.6,   'W']]
  
  indata2 = pd.DataFrame(data = indata2, columns = ['KeyData', 'Text', 'AvgAbs', 'Label'])
  
  l = indata2.Label.unique()
  m = pd.DataFrame(l, columns = ['Label'])
  m['Indicator'] = m.index + 1
  
  outputdata = indata2.merge(m[['Indicator','Label']],'left')
  
  mapper = {label: i+1 for i, label in enumerate(indata2[&quot;Label&quot;].unique())}
  indata2[&quot;Indicator&quot;] = np.select([(indata2[&quot;Label&quot;]==&quot;Q&quot;)&amp;(indata2[&quot;Text&quot;].str.contains(&quot;X&quot;)), 
                                    (indata2[&quot;Label&quot;]==&quot;Q&quot;)&amp;(indata2[&quot;Text&quot;].str.contains(&quot;Y&quot;)), 
                                    (indata2[&quot;Label&quot;]==&quot;W&quot;)&amp;(indata2[&quot;Text&quot;].str.contains(&quot;X&quot;)), 
                                    (indata2[&quot;Label&quot;]==&quot;W&quot;)&amp;(indata2[&quot;Text&quot;].str.contains(&quot;Y&quot;)),
                                    (indata2[&quot;Label&quot;].isin(list(&quot;QW&quot;))&amp;~(indata2[&quot;Text&quot;].str.contains(&quot;[X-Y]&quot;, regex=True)))
                                   ],
                                   [mapper[&quot;Q&quot;]+0.1, mapper[&quot;Q&quot;]+0.2, mapper[&quot;W&quot;]+0.1, mapper[&quot;W&quot;]+0.2, 0],
                                   indata2[&quot;Label&quot;].map(mapper))
  </code></pre>
  <p>From the indata2['Label'] column, I have two special labels: W and Q, which are grouped based on indata2['Label'] and indata2['Text'].</p>
  <p>Everything is fine, but an error occurs for the case when in indata2['Label'] the Q, W or both labels are not entered (which could happen because they are data). When that happens I have a type error: Key error.</p>
  <p>Note: The commented lines of the code are for the case where the Q, W or both labels are not entered in which case it gives me error. But it works very well when I uncomment them.</p>
  <p>What solution can be given for this case? Greetings.</p>