擅长:python、mysql、java
<p>最好的方法可能是将dataframe列作为numpy数组获取,而不必四处复制数据(在通过索引选择列之后使用<a href="http://pandas.pydata.org/pandas-docs/stable/basics.html#attributes-and-the-raw-ndarray-s" rel="nofollow noreferrer">the ^{<cd1>} property</a>),然后使用基于numpy的测试检查单调性:</p>
<pre><code>def monotonic(x):
return np.all(np.diff(x) > 0)
monotonic(df[0].values)
</code></pre>
<p>纯Python实现,从这里借用:<a href="https://stackoverflow.com/questions/4983258/python-how-to-check-list-monotonicity">Python - How to check list monotonicity</a></p>
<pre><code>def strictly_increasing(L):
return all(x<y for x, y in zip(L, L[1:]))
</code></pre>