简体   繁体   中英

Creating two different dataframes, one by selecting every nth row and the other one with the remaining data in Python?

I have created a dataframe 'new' in which I have selected every 10th row and named that as 'x_test1'. Now I want these selected rows (every 10th row) to be deleted from the previously existing dataframe 'new'. Basically I want two separate dataframes:-

  1. with every 10th row, and;
  2. other dataframe with the remaining data (excluding the data in dataframe 1)

Here's what I have tried:

x_test1 = new.iloc[::10,:] #select every 10th row from 'new' dataframe
dataset = new.drop([x_test1], axis = 0) #returns Value Error

Can someone please advise me on this?

Use drop by index values:

x_test1 = new.iloc[::10]
dataset = new.drop(x_test1.index)

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