Problems mapping a series to a min(list, key=lambda x: abs(series)) function
<p>I want to find a number in <code>series</code>, and find which number it's closest to in <code>[1,2,3]</code>. Then use the <code>key</code> to replace the series value with the appropriate letter.</p>

<pre><code>key = {1: 'A', 2:'B', 3:'C')
series = pd.Series([x*1.2 for x in range(10)])


pd.DataFrame = key[min([1,2,3], key=lambda x: abs(x-series))]
</code></pre>

<p>The <code>series</code> is a column from the <code>pd.DataFrame</code>, I've just tried to simplify it for here.</p>

<p>use the <code>apply</code> method and then <code>map</code> your <code>Series</code> such has:</p>

<pre><code>key = {1: 'A', 2:'B', 3:'C'}
series = pd.Series([x*1.2 for x in range(10)])

def find(myNumber):
    return min([1,2,3], key=lambda x:abs(x-myNumber))

series.apply(find).map(key)
Out[50]: 
0    A
1    A
2    B
3    C
4    C
5    C
6    C
7    C
8    C
9    C
dtype: object
</code></pre>

<p>it also should work if you replace series by the entire dataframe such has:</p>

<pre><code>df.apply(find).map(key)
</code></pre>

python pandas numpy dataframe series