Home>

Thank you for browsing.
As the title suggests, I want to do a loop in python that gets csv data for each chunk and calculates it, but I don't know how.

[data form]
time price
0 2020-11-07 14: 33: 35.604666 1618394.0
1 2020-11-07 14: 33: 36.697760 1618500.0
2 2020-11-07 14: 33: 37.762470 1618591.0
3 2020-11-07 14: 33: 38.868721 1618716.0
4 2020-11-07 14: 33: 39.968685 1618610.0
... ... ...
19168 2020-11-07 20: 33: 30.354527 1620369.0
19169 2020-11-07 20: 33: 31.442905 1620367.0
19170 2020-11-07 20: 33: 32.529267 1620483.0
19171 2020-11-07 20: 33: 33.653624 1620606.0
19172 2020-11-07 20: 33: 34.774001 1620653.0

[Thing I want to do]
・ Get the price on lines 0-4 and store it in a variable
・ Calculation
・ Print (calculation result)

・ Get the price on lines 1-5 and store it in a variable
・ Calculation
・ Print (calculation result)

・ Get the price on lines 2-6 and store it in a variable
・ Calculation
・ Print (calculation result)

I want to repeat it like this,
I don't know how to get 5 lines at a time.
Start → 0 End → Last 5 lines
I want to make a loop like that.
If i have any insight, please answer.

[Csv read statement]

Read data 1
import numpy as np
import pandas as pd
input_dir = "************"
input_filename = f "************. csv"
input_encoding = "shift_jis"
output_dir = ""
csv = pd.read_csv (input_dir + input_filename, encoding = input_encoding, usecols = [1, 2])