简体   繁体   中英

Python: Count the occurence of a number being smaller than a threshold accross row

I have a dataframe df with a MultIndex like this:

df.index.levels
FrozenList([[u'params', u'pvals', u'statistics', u'std'], [u'x1', u'x2', u'x3', u'x4', u'Hx5', u'adj_r2', u'r2', u'_f_test']])

You can guess that df contains an OLS output. Is there a pandas function that I can use to count how many times a number in the index pvals for each x1 x2 ... x5 is less than 0.05?

(df.ix["pvals"].ix[["x1", "x2", "x3", "x4", "x5"]] < 0.05).sum()

诀窍在于,当您在算术上下文中使用Python时,它们会将True转换为1,将False转换为0。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM