<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def compstat(sdat, tstart=None, tend=None):
 """Compute statistics from series output by StagYY. Create a file 'statistics.dat' containing the mean and standard deviation of each series on the requested time span. Args: sdat (:class:`~stagpy.stagyydata.StagyyData`):
 a StagyyData instance. tstart (float):
 starting time. Set to None to start at the beginning of available data. tend (float):
 ending time. Set to None to stop at the end of available data. """

    data = sdat.tseries_between(tstart, tend)
    time = data['t'].values
    delta_time = time[-1] - time[0]
    data = data.iloc[:, 1:].values  # assume t is first column

    mean = np.trapz(data, x=time, axis=0) / delta_time
    rms = np.sqrt(np.trapz((data - mean)**2, x=time, axis=0) / delta_time)

    with open(misc.out_name('statistics.dat'), 'w') as out_file:
        mean.tofile(out_file, sep=' ', format="%10.5e")
        out_file.write('\n')
        rms.tofile(out_file, sep=' ', format="%10.5e")
        out_file.write('\n')