How we can take mean from several excel files place wise using python

Question:

Link to Sample Data Files

I have 13 excel files in a folder, each of the excel file have 100 columns and uncertain rows (i.e.- may be from 20 to 40 rows depending upon the resultant data).

I want a single excel file which will have the average value from all files row-wise and column-wise.

For more details, I would like to take the mean of A11 rows from all 13 excel files and similarly for each and every row.

I tried taking mean through pandas mean method but it gives averaged mean of all values. I could not figure out how to take the average for each and every row.

Asked By: Harsh Singh

||

Answers:

Use:

import glob

#create list of files
files = glob.glob('Sample_Data/*.csv')
#create list of DataFrames, join to one big DataFrame
df = pd.concat([pd.read_csv(f, header=None) for f in files], axis=1)
print (df)

#get means per same columns names
df1 = df.groupby(level=0, axis=1).mean()
print (df1)
Answered By: jezrael
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.