I have dataframe pandas;
Data
Id
ID_1 19
ID_2 33
ID_3 17
ID_4 52
ID_5 17
ID_6 41
Id is index. how to drop row by index but all of ID with even number?
this is my expected result:
Data
Id
ID_1 19
ID_3 17
ID_5 17
You can select each even row by DataFrame.iloc
:
df1 = df.iloc[::2]
Or filter by mask created by numpy.arange
with modulo 2 and compare by 0
:
df1 = df[np.arange(len(df)) % 2 == 0]
print (df1)
Data
Id
ID_1 19
ID_3 17
ID_5 17
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With