0

I have a large CSV file with two columns in it as shown below:

enter image description here

I have already filtered the data. I need to calculate the average pressure every x amount of rows.

I've looked for a while on here but was unable to find how to calculate the average every x amount of rows for a specific column. Thanks for any help you can provide.

SeanK22
  • 163
  • 8
  • This? https://stackoverflow.com/questions/36810595/calculate-average-of-every-x-rows-in-a-table-and-create-new-table – Jonathan Leon Oct 06 '21 at 13:13
  • Does this answer your question? [Calculate average of every x rows in a table and create new table](https://stackoverflow.com/questions/36810595/calculate-average-of-every-x-rows-in-a-table-and-create-new-table) – Kartikey Oct 06 '21 at 21:20

1 Answers1

0

numpy - average & reshape

n = 3
x = df['Pressure']
  
# calculates the average
avgResult = np.average(givenArray.reshape(-1, n), axis=1)

the result is array, which divide columns into n sets:

eg:

array([3.33333333, 4.66666667])

in:

n=3
x = np.array([1, 4, 5,2,8,4])
Piotr Żak
  • 2,046
  • 5
  • 18
  • 30