擅长:python、mysql、java
<p>我们可以通过使用<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.eq.html" rel="nofollow noreferrer">^{<cd1>}</a>和<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.ne.html" rel="nofollow noreferrer">^{<cd2>}</a>来简化这个过程,它们代表<code>equal</code>和<code>not equal</code>。我们结合<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.head.html" rel="nofollow noreferrer">^{<cd5>}</a>和<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.tail.html" rel="nofollow noreferrer">^{<cd6>}</a>得到第一行和最后一行。你知道吗</p>
<hr/>
<pre><code>m = df['Krg'].ne(0)
n = df['Krg'].eq(0)
df.loc[m, 'Sg'].head(1).iloc[0]
df.loc[n, 'Sg'].tail(1).iloc[0]
</code></pre>
<p>输出</p>
<pre><code>0.04
0.03
</code></pre>