<p>你可以试试:</p>
<pre><code>int(str(x).split('.')[1][0])
</code></pre>
<p>这将转换为一个字符串,在上拆分。取第二部分的第一个字符,然后把它变成一个整数。得到奇怪值的原因是0.1在二进制中是一个无理数。在</p>
<p>您还可以使用:</p>
^{pr2}$
<p>这将确保您有一个整数(您可能还需要使用<code>math.round</code>)。在</p>
<p>例如:</p>
<pre><code>>>> pf = pandas.DataFrame([0.5, 4.6, 7.2, 9.8, 36.0])
>>> pf
0
0 0.5
1 4.6
2 7.2
3 9.8
4 36.0
>>> pf[0]
0 0.5
1 4.6
2 7.2
3 9.8
4 36.0
Name: 0, dtype: float64
>>> pf.apply(lambda x: int(x[0]*10.0)%10)
0 5
dtype: int64
>>> pf.apply(lambda x: int(x[0]*10.0)%10, 1)
0 5
1 6
2 2
3 8
4 0
dtype: int64
>>>
</code></pre>
<p>关于-ve编号的测试:</p>
<pre><code>>>> pf = pandas.DataFrame([0.5, 4.6, 7.2, -9.8, 36.0])
>>> df = pf.apply(lambda x: int(x[0]*10.0)%10, 1)
>>> df
0 5
1 6
2 2
3 2
4 0
dtype: int64
>>> df = pf.apply(lambda x: int(abs(x[0])*10.0)%10, 1)
>>> df
0 5
1 6
2 2
3 8
4 0
dtype: int64
>>>
</code></pre>
<p>所以我们的最终答案是:</p>
<pre><code>pf.apply(lambda x: int(abs(x[0])*10.0)%10, 1)
</code></pre>
<p>我还尝试了字符串方法:</p>
<pre><code>>>> pf.apply(lambda x:int(str(x[0]).split('.')[1][0]), 1)
0 5
1 6
2 2
3 8
4 0
dtype: int64
</code></pre>