def rolling_mean(ts, window):
    """Calculate rolling mean of time series.

    Uses pandas.DataFrame.rolling() to calculate rolling mean
    of a given window size.
    If more than one column of data in ts, returns rolling mean
    using given window size for each column of data.
    Returns nans for times before first window.

    :param ts: Time series data as a pandas DataFrame.
    :param window: Window size over which to calculate mean (int).
    :return ts_std: DataFrame with same columns as ts but with rolling
        mean in place of data column.
    """
    ts_mean = ts.rolling(window).mean()
    ts_mean["time"] = ts["time"]  # don't want mean of time!
    return ts_mean