code: def get_residual_load_from_pypsa_network(pypsa_network):
      
      residual_load = \
          pypsa_network.loads_t.p_set.sum(axis=1) - (
                  pypsa_network.generators_t.p_set.loc[
                  :, pypsa_network.generators_t.p_set.columns !=
                     'Generator_slack'].sum(axis=1) +
                  pypsa_network.storage_units_t.p_set.sum(axis=1))
      return residual_load
docs: Calculates residual load in MW in MV grid and underlying LV grids.
  
      Parameters
      ----------
      pypsa_network : :pypsa:`pypsa.Network<network>`
          The `PyPSA network
          <https://www.pypsa.org/doc/components.html#network>`_ container,
          containing load flow results.
  
      Returns
      -------
      :pandas:`pandas.Series<series>`
          Series with residual load in MW for each time step. Positiv values
          indicate a higher demand than generation and vice versa. Index of the
          series is a :pandas:`pandas.DatetimeIndex<datetimeindex>`