#NEWLINE# def to_data_frame( self , picks = None , index = None , scale_time = 1000.0 , scalings = None , copy = True , start = None , stop = None ) : #NEWLINE# #INDENT# "Export data in tabular structure as a pandas DataFrame.\n\n        Columns and indices will depend on the object being converted.\n        Generally this will include as much relevant information as\n        possible for the data type being converted. This makes it easy\n        to convert data for use in packages that utilize dataframes,\n        such as statsmodels or seaborn.\n\n        Parameters\n        ----------\n        picks : array-like of int | None\n            If None only MEG and EEG channels are kept\n            otherwise the channels indices in picks are kept.\n        index : tuple of str | None\n            Column to be used as index for the data. Valid string options\n            are 'epoch', 'time' and 'condition'. If None, all three info\n            columns will be included in the table as categorial data.\n        scale_time : float\n            Scaling to be applied to time units.\n        scalings : dict | None\n            Scaling to be applied to the channels picked. If None, defaults to\n            ``scalings=dict(eeg=1e6, grad=1e13, mag=1e15, misc=1.0)``.\n        copy : bool\n            If true, data will be copied. Else data may be modified in place.\n        start : int | None\n            If it is a Raw object, this defines a starting index for creating\n            the dataframe from a slice. The times will be interpolated from the\n            index and the sampling rate of the signal.\n        stop : int | None\n            If it is a Raw object, this defines a stop index for creating\n            the dataframe from a slice. The times will be interpolated from the\n            index and the sampling rate of the signal.\n\n        Returns\n        -------\n        df : instance of pandas.core.DataFrame\n            A dataframe suitable for usage with other\n            statistical/plotting/analysis packages. Column/Index values will\n            depend on the object type being converted, but should be\n            human-readable.\n        " #NEWLINE# from .. epochs import _BaseEpochs #NEWLINE# from .. evoked import Evoked #NEWLINE# from .. source_estimate import _BaseSourceEstimate #NEWLINE# pd = _check_pandas_installed ( ) #NEWLINE# mindex = list ( ) #NEWLINE# if isinstance ( self , _BaseSourceEstimate ) : #NEWLINE# #INDENT# if ( self . subject is None ) : #NEWLINE# #INDENT# default_index = [ 'time' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# default_index = [ 'subject' , 'time' ] #NEWLINE# #UNINDENT# data = self . data . T #NEWLINE# times = self . times #NEWLINE# shape = data . shape #NEWLINE# mindex . append ( ( 'subject' , np . repeat ( self . subject , shape [ 0 ] ) ) ) #NEWLINE# if isinstance ( self . vertices , list ) : #NEWLINE# #INDENT# col_names = [ i for e in [ [ '{0} {1}' . format ( ( 'LH' if ( ii < 1 ) else 'RH' ) , vert ) for vert in vertno ] for ( ii , vertno ) in enumerate ( self . vertices ) ] for i in e ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# col_names = [ 'VOL {0}' . format ( vert ) for vert in self . vertices ] #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( self , ( _BaseEpochs , _BaseRaw , Evoked ) ) : #NEWLINE# #INDENT# picks = self . _get_check_picks ( picks , self . ch_names ) #NEWLINE# if isinstance ( self , _BaseEpochs ) : #NEWLINE# #INDENT# default_index = [ 'condition' , 'epoch' , 'time' ] #NEWLINE# data = self . get_data ( ) [ : , picks , : ] #NEWLINE# times = self . times #NEWLINE# ( n_epochs , n_picks , n_times ) = data . shape #NEWLINE# data = np . hstack ( data ) . T #NEWLINE# times = np . tile ( times , n_epochs ) #NEWLINE# id_swapped = dict ( ( ( v , k ) for ( k , v ) in self . event_id . items ( ) ) ) #NEWLINE# names = [ id_swapped [ k ] for k in self . events [ : , 2 ] ] #NEWLINE# mindex . append ( ( 'condition' , np . repeat ( names , n_times ) ) ) #NEWLINE# mindex . append ( ( 'epoch' , np . repeat ( np . arange ( n_epochs ) , n_times ) ) ) #NEWLINE# col_names = [ self . ch_names [ k ] for k in picks ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( self , ( _BaseRaw , Evoked ) ) : #NEWLINE# #INDENT# default_index = [ 'time' ] #NEWLINE# if isinstance ( self , _BaseRaw ) : #NEWLINE# #INDENT# ( data , times ) = self [ picks , start : stop ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( self , Evoked ) : #NEWLINE# #INDENT# data = self . data [ picks , : ] #NEWLINE# times = self . times #NEWLINE# ( n_picks , n_times ) = data . shape #NEWLINE# #UNINDENT# #UNINDENT# data = data . T #NEWLINE# col_names = [ self . ch_names [ k ] for k in picks ] #NEWLINE# #UNINDENT# #UNINDENT# types = [ channel_type ( self . info , idx ) for idx in picks ] #NEWLINE# n_channel_types = 0 #NEWLINE# ch_types_used = [ ] #NEWLINE# scalings = _handle_default ( 'scalings' , scalings ) #NEWLINE# for t in scalings . keys ( ) : #NEWLINE# #INDENT# if ( t in types ) : #NEWLINE# #INDENT# n_channel_types += 1 #NEWLINE# ch_types_used . append ( t ) #NEWLINE# #UNINDENT# #UNINDENT# for t in ch_types_used : #NEWLINE# #INDENT# scaling = scalings [ t ] #NEWLINE# idx = [ picks [ i ] for i in range ( len ( picks ) ) if ( types [ i ] == t ) ] #NEWLINE# if ( len ( idx ) > 0 ) : #NEWLINE# #INDENT# data [ : , idx ] *= scaling #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise NameError ( ( 'Object must be one of Raw, Epochs, Evoked,  or ' + 'SourceEstimate. This is {0}' . format ( type ( self ) ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# times = np . round ( ( times * scale_time ) ) #NEWLINE# mindex . append ( ( 'time' , times ) ) #NEWLINE# if ( index is not None ) : #NEWLINE# #INDENT# _check_pandas_index_arguments ( index , default_index ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# index = default_index #NEWLINE# #UNINDENT# if ( copy is True ) : #NEWLINE# #INDENT# data = data . copy ( ) #NEWLINE# #UNINDENT# assert all ( ( ( len ( mdx ) == len ( mindex [ 0 ] ) ) for mdx in mindex ) ) #NEWLINE# df = pd . DataFrame ( data , columns = col_names ) #NEWLINE# for ( i , ( k , v ) ) in enumerate ( mindex ) : #NEWLINE# #INDENT# df . insert ( i , k , v ) #NEWLINE# #UNINDENT# if ( index is not None ) : #NEWLINE# #INDENT# if ( 'time' in index ) : #NEWLINE# #INDENT# logger . info ( 'Converting time column to int64...' ) #NEWLINE# df [ 'time' ] = df [ 'time' ] . astype ( np . int64 ) #NEWLINE# #UNINDENT# df . set_index ( index , inplace = True ) #NEWLINE# #UNINDENT# if all ( ( ( i in default_index ) for i in index ) ) : #NEWLINE# #INDENT# df . columns . name = 'signal' #NEWLINE# #UNINDENT# return df