I have an example data frame as follows. I am trying to calculate the data for each column by combining them together on the "Sample_ID" column. That is, I would calculate the mean and standard deviation for the first column of each group "Sample_ID" (1, 2 and 3). I can do this for one or even several columns. For my new data, I have 100 columns.
df = pd.DataFrame([[1, 1.0, 2.3,0.2,0.53], [2, 3.35, 2.0,0.2,0.65], [2,3.4,
2.0,0.25,0.55], [3,3.4,2.0,0.25,0.55], [1,3.4,2.0,0.25,0.55],
[3,3.4,2.0,0.25,0.55]],
columns=["Sample_ID", "NaX", "NaU","OC","EC"])\
.set_index('Sample_ID')
Is there a way to iterate over each column and save them? Here is a calculation example for one data column, I need to do this calculation for 100 data columns.
Thanks for reading this!
OC_UNC=100*np.sqrt((((df.groupby(['Sample_ID'])['OC'].std()
/df.groupby(['Sample_ID'])['OC'].mean())**2).sum()
)/len((df.groupby(['Sample_ID'])['OC'].count())))