[英]Buffer has wrong number of dimensions (expected 1, got 2)
I need to select the first 2000 rows of a dataframe if the groupby
count of the particular column is greater than 2000. How can this be done in python?如果特定列的groupby
计数大于 2000,我需要 select dataframe 的前 2000 行。如何在 Z23EEEB4347BDD26BFC6B7EE9A3B75 中完成此操作? Is the below one is the correct way of doing下面是正确的做法吗
X_train[ 1:2000, X_train.groupby(['value']).count() > 2000].
I am getting Buffer has wrong number of dimensions (expected 1, got 2)
我得到Buffer has wrong number of dimensions (expected 1, got 2)
Please help me in selecting 2000 rows if particular column group by count exceeds 2000.如果按计数的特定列组超过 2000,请帮助我选择 2000 行。
df = pd.DataFrame(np.random.randint(1, 10, 100).reshape((20,5)))
col = 0
lower_bnd = 2
n_rows = 3
count = df.groupby([col]).size()
selection = count[count > lower_bnd].index
dg = df.loc[df[col].isin(selection)].iloc[:n_rows]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.