Подсчет значений, которые удовлетворяют условию

Вы можете сделать что-то подобное, как на одном рисунке:

In [4]: Df = pd.DataFrame(data=np.random.randn(10,4), index=pd.DatetimeIndex(start='2005', freq='M', periods=10), columns=['A','B','C','D'])

In [5]: fig, ax = plt.subplots(2, 1) # you can pass sharex=True, sharey=True if you want to share axes.

In [6]: Df[['A','B']].plot(kind='bar', ax=ax[0])
Out[6]: <matplotlib.axes.AxesSubplot at 0x10cf011d0>

In [7]: Df[['C','D']].plot(color=['r', 'c'], ax=ax[1])
Out[7]: <matplotlib.axes.AxesSubplot at 0x10a656ed0>
0
задан Dev-iL 21 February 2019 в 13:23
поделиться

1 ответ

Эта задача может выиграть от векторизации:

n = 500
AA = rand(n,1); % You used vectorization already (!) and not create each entry separately...
BB = AA>0.5;    % Results in a vector of logicals which signifies where the condition was met
SD = sum(BB)/n; % Can also be `nnz(BB)/n` or `mean(BB)`
0
ответ дан 2 revs, 2 users 93% 21 February 2019 в 13:23
поделиться
Другие вопросы по тегам:

Похожие вопросы: