I am reading an excel file and I was wondering how I could create a loop that reads specific rows based on a pattern. Let's say for example I want to read the first three rows from my excel sheet (which correspond to 0,1,2) and then read rows 10,11,12 (which correspond to 9,10,11) and so on. The total number of rows is 156.
Hypothesis:
import numpy as np
import pandas as pd
df = pd.read_excel("My Excel.xlsx")
a = df.iloc[[0,1,2]]
b = [x + 1 for x in a]
My code as it is right now.
import numpy as np
import pandas as pd
df = pd.read_excel("My Excel.xlsx")
A1 = df.iloc[[0,1,2]].mean() #This is my data transformation
A11 = 1 /(numpy.log10(A2)) # This is also
A2 = df.iloc[[9,10,11]].mean()
A22 = 1/(numpy.log10(A2)).mean()
....
.... Doing this procedure for other teams of data (3 rows each team)
A17 = df.iloc[[146,147,148]].mean()
A177 = 1/(numpy.log10(A17))
So my question is how can I create a loop choosing specific rows out of my Excel file and applying my transformations to it without doing each one at a time. What if I had 1000 data; It would be a disaster.
Thank you for your time. With respect!