简体   繁体   中英

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? 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)

Please help me in selecting 2000 rows if particular column group by count exceeds 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]

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