def to_frame(self, filter_observations=True):
_, N, K = self.shape<EOL>if filter_observations:<EOL><INDENT>mask = notna(self.values).all(axis=<NUM_LIT:0>)<EOL>selector = mask.ravel()<EOL><DEDENT>else:<EOL><INDENT>selector = slice(None, None)<EOL><DEDENT>data = {item: self[item].values.ravel()[selector]<EOL>for item in self.items}<EOL>def construct_multi_parts(idx, n_repeat, n_shuffle=<NUM_LIT:1>):<EOL><INDENT>codes = [np.repeat(x, n_repeat) for x in idx.codes]<EOL>codes = [x.reshape(n_shuffle, -<NUM_LIT:1>).ravel(order='<STR_LIT:F>')<EOL>for x in codes]<EOL>codes = [x[selector] for x in codes]<EOL>levels = idx.levels<EOL>names = idx.names<EOL>return codes, levels, names<EOL><DEDENT>def construct_index_parts(idx, major=True):<EOL><INDENT>levels = [idx]<EOL>if major:<EOL><INDENT>codes = [np.arange(N).repeat(K)[selector]]<EOL>names = idx.name or '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>codes = np.arange(K).reshape(<NUM_LIT:1>, K)[np.zeros(N, dtype=int)]<EOL>codes = [codes.ravel()[selector]]<EOL>names = idx.name or '<STR_LIT>'<EOL><DEDENT>names = [names]<EOL>return codes, levels, names<EOL><DEDENT>if isinstance(self.major_axis, MultiIndex):<EOL><INDENT>major_codes, major_levels, major_names = construct_multi_parts(<EOL>self.major_axis, n_repeat=K)<EOL><DEDENT>else:<EOL><INDENT>major_codes, major_levels, major_names = construct_index_parts(<EOL>self.major_axis)<EOL><DEDENT>if isinstance(self.minor_axis, MultiIndex):<EOL><INDENT>minor_codes, minor_levels, minor_names = construct_multi_parts(<EOL>self.minor_axis, n_repeat=N, n_shuffle=K)<EOL><DEDENT>else:<EOL><INDENT>minor_codes, minor_levels, minor_names = construct_index_parts(<EOL>self.minor_axis, major=False)<EOL><DEDENT>levels = major_levels + minor_levels<EOL>codes = major_codes + minor_codes<EOL>names = major_names + minor_names<EOL>index = MultiIndex(levels=levels, codes=codes, names=names,<EOL>verify_integrity=False)<EOL>return DataFrame(data, index=index, columns=self.items)<EOL>
Transform wide format into long (stacked) format as DataFrame whose
columns are the Panel's items and whose index is a MultiIndex formed
of the Panel's major and minor axes.

Parameters
----------
filter_observations : boolean, default True
    Drop (major, minor) pairs without a complete set of observations
    across all the items

Returns
-------
y : DataFrame