Remove numbers from a string with a letter in front
<pre><code>combined['Cabin'] = combined['Cabin'].map(lambda c : c[0])
</code></pre>

<p>I'm following a tutorial, except this line throws the error <code>TypeError: 'float' object has no attribute '__getitem__'</code></p>

<p>Anyway to fix this? </p>

<p>My column's data looks like
<a href="http://i.stack.imgur.com/dYHmw.png" rel="nofollow">Column</a></p>

<p>Thanks!</p>

<pre><code>def process_cabin():

global combined

# replacing missing cabins with U (for Unknown)
combined.Cabin.fillna('U',inplace=True)

# mapping each Cabin value with the cabin letter
combined['Cabin'] = combined['Cabin'].map(lambda c : c[0])

# dummy encoding ...
cabin_dummies = pd.get_dummies(combined['Cabin'],prefix='Cabin')

combined = pd.concat([combined,cabin_dummies],axis=1)

combined.drop('Cabin',axis=1,inplace=True)

status('cabin')
</code></pre>

<p>`</p>

<pre><code>---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
&lt;ipython-input-152-70714b711c6d&gt; in &lt;module&gt;()
----&gt; 1 process_cabin()

&lt;ipython-input-151-d9bb11cabd2c&gt; in process_cabin()
      7 
      8     # mapping each Cabin value with the cabin letter
----&gt; 9     combined['Cabin'] = combined['Cabin'].map(lambda c : c[0])
     10 
     11 

C:\Users\Data.Steve-PC\Python\Anaconda\lib\site-packages\pandas\core\series.pyc in map(self, arg, na_action)
   2014                                      index=self.index).__finalize__(self)
   2015         else:
-&gt; 2016             mapped = map_f(values, arg)
   2017             return self._constructor(mapped,
   2018                                      index=self.index).__finalize__(self)

pandas\src\inference.pyx in pandas.lib.map_infer (pandas\lib.c:58435)()

&lt;ipython-input-151-d9bb11cabd2c&gt; in &lt;lambda&gt;(c)
      7 
      8     # mapping each Cabin value with the cabin letter
----&gt; 9     combined['Cabin'] = combined['Cabin'].map(lambda c : c[0])
     10 
     11 

TypeError: 'float' object has no attribute '__getitem__'
</code></pre>

<p>I suspect the problem is that your <code>X</code> isn't what you think it is. If it's a float, for example, 123.45:</p>

<p><code>&gt;&gt;&gt; 123.45['Y']</code><br>
<code>Traceback (most recent call last):</code><br>
<code>File "&lt;stdin&gt;", line 1, in &lt;module&gt;</code><br>
<code>TypeError: 'float' object has no attribute '__getitem__'</code>  </p>

python