Pandas every nth row

Mixel picture Mixel · Jul 31, 2014 · Viewed 97.7k times · Source

Dataframe.resample() works only with timeseries data. I cannot find a way of getting every nth row from non-timeseries data. What is the best method?

Answer

chrisb picture chrisb · Jul 31, 2014

I'd use iloc, which takes a row/column slice, both based on integer position and following normal python syntax. If you want every 5th row:

df.iloc[::5, :]