How to select only alternate lines in a dataframe?

Asked

Viewed 79 times

1

After greatly refining my data, I now need to just pick up the alternate lines from it. Example, Indice 239, 444, etc. An idea would be to rename these index to 0,1,2... and ask to select only the odd ones for example. But I’m having a hard time with how to do this, I hardly do pandas, and I don’t know all the features. I’d really appreciate the help! inserir a descrição da imagem aqui

1 answer

1


I believe you only need to reset the index and select only the odd index, like this:

Resetting index:

df.reset_index(drop=True, inplace=True)

Select only odd index:

df[df.index%2 != 0]
  • Hi, in the meantime, I had reset the index to be with him starting from scratch. I used iloc. that the boys had said, and I tested this yours too, both worked perfectly! Thank you very much! They are simple things, but as I don’t work with data, sometimes I need to do these refinements and spend a lot of time researching, but this is how we learn! One thing: if I want to delete multiple columns at once, example: del df. ['Time','N2'] does not work. It only works if it’s one by one, the syntax is wrong?

  • @user217614 Use the drop

Browser other questions tagged

You are not signed in. Login or sign up in order to post.