#NEWLINE# def stack_measures( self , measures , ids = None , var_name = 'variable' , value_name = 'value' ) : #NEWLINE# #INDENT# "De-pivots `_data` from a 'wide' to 'tall' layout.\n\n        A wide table is one where the column names represent a categorical variable\n        and each contains only the values associated with each unique value of the\n        categorical variable.\n\n        This method uses the :func:`pandas.melt` function with additional logic\n        to make sure that the same data source can have multiple operations applied,\n        and so all other columns are maintained through the stacking process.\n\n        Example:\n\n            .. note::\n\n                This example is fairly low level and is not something the typical\n                user should worry about. The interface for data transformations from\n                the user perspective are the :ref:`bokeh_charts_functions`.\n\n            >>> data = {'a': [1, 2, 3, 4],\n            ...         'b': [2, 3, 4, 5],\n            ...         'month': ['jan', 'jan', 'feb', 'feb']\n            ...         }\n\n            >>> ds = ChartDataSource.from_data(data)\n            >>> ds['x'] =['a', 'b'] # say we selected a and b for dimension x\n\n            We may want to combine 'a' and 'b' together. The final\n            data would look like the following:\n\n            >>> ds.stack_measures(['c', 'd'], var_name='c_d_variable',\n            ...                   value_name='c_d_value')\n            >>> ds.df\n            Out[35]:\n                  month a_b_variable  a_b_value\n                0   jan            a          1\n                1   jan            a          2\n                2   feb            a          3\n                3   feb            a          4\n                4   jan            b          2\n                5   jan            b          3\n                6   feb            b          4\n                7   feb            b          5\n\n            The transformed data will use the `var_name` and `value_name` inputs to\n            name the columns. These derived columns can then be used as a single column\n            to reference the values and the labels of the data. In the example, I could\n            plot a_b_value vs month, and color by a_b_variable.\n\n            What this does for you over the :meth:`pandas.melt` method is that it will\n            apply the :class:`DataOperator` for a dimension if it exists (e.g.\n            :class:`Blend`, generated by :func:`blend`), and it will try to handle the id\n            columns for you so you don't lose other columns with the melt transformation.\n\n        Returns:\n            None\n\n        " #NEWLINE# for dim in self . _dims : #NEWLINE# #INDENT# selection = self . _selections [ dim ] #NEWLINE# if isinstance ( selection , DataOperator ) : #NEWLINE# #INDENT# dim_cols = selection . columns #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# dim_cols = selection #NEWLINE# #UNINDENT# if ( var_name in self . df . columns . tolist ( ) ) : #NEWLINE# #INDENT# var_name += '_' #NEWLINE# #UNINDENT# if ( measures == dim_cols ) : #NEWLINE# #INDENT# self . _selections [ dim ] = value_name #NEWLINE# if ( ids is not None ) : #NEWLINE# #INDENT# if all ( [ ( measure in self . df . columns . tolist ( ) ) for measure in measures ] ) : #NEWLINE# #INDENT# self . _data = pd . melt ( self . _data , id_vars = ids , value_vars = measures , var_name = var_name , value_name = value_name ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# ids = list ( ( set ( self . _data . columns ) - set ( measures ) ) ) #NEWLINE# self . _data = pd . melt ( self . _data , id_vars = ids , value_vars = measures , var_name = var_name , value_name = value_name )