1

I am using a CSV file with over 1,000,000 rows of data, however I need to export every 10th row into a new CSV.

The current CSV looks like this:

Date-Time   Weight(g)
26:07.1 -0.09
26:07.2 -0.09
26:07.3 -0.09
26:07.4 -0.09
26:07.5 -0.09
26:07.6 -0.09
26:07.7 -0.09
26:07.8 -0.09
26:07.9 81.05
26:07.9 81.02
26:08.0 80.98
26:08.1 81
Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91
ayejerm
  • 11
  • 1
  • Can you share what you tried ? – Nir Elbaz Apr 04 '22 at 14:07
  • def logic(index): if index % 3 == 0: return True return False I'm very new to Python but trying to learn for my job. I need to grab every 10th row and I have headers. TYIA – ayejerm Apr 04 '22 at 14:10
  • why 3 in you want 10th? – Nir Elbaz Apr 04 '22 at 14:11
  • That's just the example I used from online. Would changing that to 10 give me every 10 rows? I need to import a CSV file, then filter out every 10th row, then put that into a CSV file and don't know how to export that into a CSV either – ayejerm Apr 04 '22 at 14:17

1 Answers1

0

You can slice your dataframe and then export it:

df.iloc[::10, :].to_csv(filepath)

See also this answer here

ibmx
  • 173
  • 9