Calculate the mean from excel sheet for specific rows

0 votes

Dear Friends: I'm having trouble using Python to determine the mean of certain rows from an excel sheet. In particular, starting with the first three rows and going to the next three and so forth, I would want to calculate the mean for each set of three rows. 156 rows of data are on my excel sheet. This is how my data sheet looks:

enter image description here

And this is my code: 
import numpy 
import pandas as pd
df = pd.read_excel("My Excel.xlsx")
x = df.iloc[[0,1,2], [9,10,11]].mean()
print(x)

In summary, I'm attempting to use a single line of code or some sort of index to get the means of Part 1 Measurements 1 (rows 1, 2, and 3), and Part 2 Measurements 1 (rows 9, 10, and 11). Two lists of numbers, one representing the mean of Part 1 Measurement 1 (rows 1, 2, and 3), and the other representing the mean of Part 2 Measurements 1 are what I'm anticipating receiving (rows 10,11,12). Additionally, I am aware that Python considers the first row as 0. The index must take the form n+1.

Nov 29, 2022 in Others by Kithuzzz
• 38,000 points
850 views

1 answer to this question.

0 votes

Generate a list for each means you want to calculate:

x1, x2 = list(df.iloc[[0,1,2]].mean()), list(df.iloc[[9,10,11]].mean())

Or you could also generate a list of lists:

x = [list(df.iloc[[0,1,2]].mean()), list(df.iloc[[9,10,11]].mean())]
answered Dec 10, 2022 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
1 answer

How can I copy from specific sheet in excel

You should use wb.Sheets("Name of sheet").Copy - ...READ MORE

answered Oct 29, 2022 in Others by narikkadan
• 63,600 points
497 views
0 votes
1 answer
0 votes
1 answer

Hiding the formula bar in Excel for a specific file

No, you cannot. Unfortunately, altering the CustomUI file ...READ MORE

answered Dec 17, 2022 in Others by narikkadan
• 63,600 points
721 views
0 votes
1 answer

How do you populate a google sheets/excel column with cells from a column in another sheet in the same document?

You have two options on chronology: sheet-by-sheet =QUERY({Sheet1!X:Z; Sheet2!X:Z; ...READ MORE

answered Dec 19, 2022 in Others by narikkadan
• 63,600 points
1,598 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
0 votes
1 answer

How do you calculate the Quintile for groups of rows in Excel?

Use this formula: =MAX(1,ROUNDUP(10*PERCENTRANK($C:$C,$C2,4),0)) To divide into whichever many ...READ MORE

answered Oct 17, 2022 in Others by narikkadan
• 63,600 points
1,338 views
0 votes
1 answer

Excel VBA remove blank rows from specific range

I have tried to avoid .select  Option Explicit Sub CombineData() ...READ MORE

answered Oct 23, 2022 in Others by narikkadan
• 63,600 points
1,111 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP