Issue
df_o = pd.DataFrame(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o'])
I would like to continuously delete 4 consecutive rows but always spare the fifth in the dataframe above. The final result should be:
df_o = pd.DataFrame(['e', 'j', 'o'])
My idea df_o = df_o.drop(df_o.iloc[::0.2].index)
does not work. It works well for deleting every n-th row if n is an integer, but not for my case.
Solution
Try this:
df_o.groupby(np.arange(len(df_o.index))//5).last()
Output:
0
0 e
1 j
2 o
Answered By - rhug123
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.