'Processing excel sheet in python
I have an excel sheet with a list of experiments, as shown in the picture below. How can I access specific rows and columns to find the mean and std dev? I am able to load the excel file and read the data using pandas, but I am not sure where to go from there. Ideally, the code can process sheets with many experiment results listed.
For output, I would like a table summarizing the results, as shown in the picture below:
Solution 1:[1]
I am not sure if this is efficient solution, but this will do.
import pandas as pd
df = pd.read_excel("~/Desktop/delete.xlsx", header=None).T
df.dropna(axis=1, inplace = True)
df.rename(columns=df.iloc[0], inplace = True)
df.drop(df.index[0], inplace = True)
cols = df.columns.unique()
df1 = pd.DataFrame(df.values.reshape(3, 8), columns=cols)
df1['mean'] = df1[df1.columns[~df1.columns.isin(['Test','Sample', 'Site'])]].mean(axis=1)
df1['std'] = df1[df1.columns[~df1.columns.isin(['Test','Sample', 'Site'])]].std(axis=1)
print(df1[['Sample', 'mean', 'std']])
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Henry Ecker |
