code: def binned(data: pd.Series, nbins: Optional[int] = None) -> pd.Series:
      """Bins the data in ``nbins`` bins.
  
      Args:
          data (pd.Series): Timeseries to bin.
          nbins (Optional[int]): Number of bins, if not provided uses the Freedman-Diaconis rule to
              calculate the number of bins: bw=2×IQR×n^{−1/3}; n_bins=(max−min)/bw
  
      Returns:
          pd.Series: Series with the counts, indexed by bins.
      """
      data = data.copy().dropna()
      if not nbins:
          # Freedman-Diaconis rule: bin-width is set to bw=2×IQR×n^{−1/3}; n_bins=(max−min)/bw
          bw = 2 * iqr(data) * len(data) ** (-1 / 3)
          nbins = round((max(data) - min(data)) / bw)
      counts, bins = np.histogram(data.values, nbins)
      return pd.Series(counts, index=bins[:-1])
  
file_path: tslumen/tslumen/profile/distribution.py
imports: from typing import Optional
  import numpy
  import pandas
  from scipy.stats import iqr
  from statsmodels.api import ProbPlot
  from tslumen.profile.base import ProfilingFunction
label_desc: Use image node_id 1 for calling a global function with example usage: binned(data, nbins) and returns: pd