Hi chenhongjun ,
Sorry for the delay in updating this. I have found the problem. Here is an updated version. Please let me know if you have any troubles with it:
import pandas as pd
from iolite.QtGui import QFileDialog
from iolite.QtCore import QDir
import sys
def getValuesDF(mode):
"""
Returns a pandas data frame for all selections in all groups (except
Baselines).
The value for each selection to be returned is based on mode:
Mean: mean of selection
OneSD: uncertainty as 1 SD
LOD: LOD (currently just Longerich value)
Returns pandas dataframe with columns as channels, and each row as a
selection
NOTE: The headers are un-named in the returned dataframe. This makes it
easier to concat/append dataframes
"""
df = pd.DataFrame()
selNames = []
for group in data.selectionGroupList():
if group.type == data.Baseline:
continue
counter = 1
for sel in group.selections():
if mode == 'Mean':
res = [data.result(sel, ch).value() for ch in data.timeSeriesList(data.Output)]
elif mode == 'OneSD':
res = [data.result(sel, ch).uncertainty("Basic", "AbsOneStdDev") for ch in data.timeSeriesList(data.Output)]
elif mode == 'LOD':
res = [data.result(sel, ch).longerichLOD() for ch in data.timeSeriesList(data.Output)]
else:
print("ERROR: mode argument must be one of \"Mean\", \"OneSD\", or \"LOD\"")
return
if sel.name in df.columns:
this_sel_name = sel.name + '_' + str(counter)
counter += 1
else:
this_sel_name = sel.name
df[this_sel_name] = res
selNames.append(this_sel_name)
# Now transpose it so that each selection is a row instead of a column
df = df.transpose()
# And add the sel name as column
df.insert(0, 'Name', selNames)
return df
df_vals = getValuesDF('Mean')
df_vals = df_vals.append(pd.Series(), ignore_index=True)
df_unc = getValuesDF('OneSD')
df_unc = df_unc.append(pd.Series(), ignore_index=True)
df_lod = getValuesDF('LOD')
df_final = pd.concat([df_vals, df_unc, df_lod])
# Add the column headings:
headers = [channel.name for channel in data.timeSeriesList(data.Output)]
headers.insert(0, 'Selection Name')
df_final.set_axis(headers, axis=1, inplace=True)
fname = QFileDialog.getSaveFileName(None, "Save Export Data", QDir.homePath(), "CSV Files (*.csv")
if fname:
df_final.to_csv(fname, index=False)
print(f"Saved to {fname}")
-Bence