pandas_bridge - Bridge to the pandas library

Bridge to the pandas library.

elephant.pandas_bridge.epoch_to_dataframe(epoch, parents=True, child_first=True)[source]

Convert a neo.core.Epoch to a pandas.DataFrame.

The pandas.DataFrame object has a single column, with each element being the epoch label from the epoch.label attribute.

The column heading is a pandas.MultiIndex with one index for each of the scalar attributes and annotations. The index is a pandas.MultiIndex, with the first index being the time stamp from the epoch.times attribute and the second being the duration from the epoch.durations attribute.

Parameters:
epoch : neo Epoch

The Epoch to convert.

parents : bool, optional

Also include attributes and annotations from parent neo objects (if any).

child_first : bool, optional

If True (default True), values of child attributes are used over parent attributes in the event of a name conflict. If False, parent attributes are used. This parameter does nothing if parents is False.

Returns:
pandas DataFrame

A DataFrame containing the labels from epoch.

Notes

If the length of epoch.times, epoch.duration, and epoch.labels are not the same, the longer will be truncated to the length of the shortest.

The index names for epoch.times and epoch.durations are times and durations, respectively.

Attributes that contain non-scalar values are skipped. So are annotations or attributes containing a value of None.

quantity.Quantities types are incompatible with pandas, so attributes and annotations of that type are converted to a tuple where the first element is the scalar value and the second is the string representation of the units.

elephant.pandas_bridge.event_to_dataframe(event, parents=True, child_first=True)[source]

Convert a neo.core.Event to a pandas.DataFrame.

The pandas.DataFrame object has a single column, with each element being the event label from the event.label attribute.

The column heading is a pandas.MultiIndex with one index for each of the scalar attributes and annotations. The index is the time stamp from the event.times attribute.

Parameters:
event : neo Event

The Event to convert.

parents : bool, optional

Also include attributes and annotations from parent neo objects (if any).

child_first : bool, optional

If True (default True), values of child attributes are used over parent attributes in the event of a name conflict. If False, parent attributes are used. This parameter does nothing if parents is False.

Returns:
pandas DataFrame

A DataFrame containing the labels from event.

Notes

If the length of event.times and event.labels are not the same, the longer will be truncated to the length of the shorter.

The index name is times.

Attributes that contain non-scalar values are skipped. So are annotations or attributes containing a value of None.

quantity.Quantities types are incompatible with pandas, so attributes and annotations of that type are converted to a tuple where the first element is the scalar value and the second is the string representation of the units.

elephant.pandas_bridge.multi_epochs_to_dataframe(container, parents=True, child_first=True)[source]

Convert one or more neo.Epoch objects to a pandas.DataFrame.

The objects can be any list, dict, or other iterable or mapping containing epochs, as well as any neo object that can hold epochs: neo.Block and neo.Segment. Objects are searched recursively, so the objects can be nested (such as a list of blocks).

The pandas.DataFrame object has one column for each epoch, with each element being the epoch label. columns are padded to the same length with NaN values.

The column heading is a pandas.MultiIndex with one index for each of the scalar attributes and annotations of the respective epoch. The index is a pandas.MultiIndex, with the first index being the time stamp from the epoch.times attribute and the second being the duration from the epoch.durations attribute.

Parameters:
container : list, tuple, iterable, dict, neo Block, neo Segment

The container for the epochs to convert.

parents : bool, optional

Also include attributes and annotations from parent neo objects (if any).

child_first : bool, optional

If True (default True), values of child attributes are used over parent attributes in the event of a name conflict. If False, parent attributes are used. This parameter does nothing if parents is False.

Returns:
pandas DataFrame

A DataFrame containing the labels from container.

Notes

If the length of epoch.times, epoch.duration, and epoch.labels are not the same for any individual epoch, the longer will be truncated to the length of the shorter for that epoch. Between epochs, lengths can differ.

The index level names for epoch.times and epoch.durations are times and durations, respectively.

Attributes that contain non-scalar values are skipped. So are annotations or attributes containing a value of None.

quantity.Quantities types are incompatible with pandas, so attributes and annotations of that type are converted to a tuple where the first element is the scalar value and the second is the string representation of the units.

elephant.pandas_bridge.multi_events_to_dataframe(container, parents=True, child_first=True)[source]

Convert one or more neo.Event objects to a pandas.DataFrame.

The objects can be any list, dict, or other iterable or mapping containing events, as well as any neo object that can hold events: neo.Block and neo.Segment. Objects are searched recursively, so the objects can be nested (such as a list of blocks).

The pandas.DataFrame object has one column for each event, with each element being the event label. columns are padded to the same length with NaN values.

The column heading is a pandas.MultiIndex with one index for each of the scalar attributes and annotations of the respective event. The index is the time stamp from the event.times attribute.

Parameters:
container : list, tuple, iterable, dict, neo Block, neo Segment

The container for the events to convert.

parents : bool, optional

Also include attributes and annotations from parent neo objects (if any).

child_first : bool, optional

If True (default True), values of child attributes are used over parent attributes in the event of a name conflict. If False, parent attributes are used. This parameter does nothing if parents is False.

Returns:
pandas DataFrame

A DataFrame containing the labels from container.

Notes

If the length of event.times and event.labels are not the same for any individual event, the longer will be truncated to the length of the shorter for that event. Between events, lengths can differ.

The index name is times.

Attributes that contain non-scalar values are skipped. So are annotations or attributes containing a value of None.

quantity.Quantities types are incompatible with pandas, so attributes and annotations of that type are converted to a tuple where the first element is the scalar value and the second is the string representation of the units.

elephant.pandas_bridge.multi_spiketrains_to_dataframe(container, parents=True, child_first=True)[source]

Convert one or more neo.SpikeTrain objects to a pandas.DataFrame.

The objects can be any list, dict, or other iterable or mapping containing spiketrains, as well as any neo object that can hold spiketrains: neo.Block, neo.ChannelIndex, neo.Unit, and neo.Segment. Objects are searched recursively, so the objects can be nested (such as a list of blocks).

The pandas.DataFrame object has one column for each spiketrain, with each element being the spike time converted to a float value in seconds. columns are padded to the same length with NaN values.

The column heading is a pandas.MultiIndex with one index for each of the scalar attributes and annotations of the respective spiketrain. The index is the spike number.

Parameters:
container : list, tuple, iterable, dict,

neo Block, neo Segment, neo Unit, neo ChannelIndex The container for the spiketrains to convert.

parents : bool, optional

Also include attributes and annotations from parent neo objects (if any).

child_first : bool, optional

If True (default True), values of child attributes are used over parent attributes in the event of a name conflict. If False, parent attributes are used. This parameter does nothing if parents is False.

Returns:
pandas DataFrame

A DataFrame containing the spike times from container.

Notes

The index name is spike_number.

Attributes that contain non-scalar values are skipped. So are annotations or attributes containing a value of None.

quantity.Quantities types are incompatible with pandas, so attributes and annotations of that type are converted to a tuple where the first element is the scalar value and the second is the string representation of the units.

elephant.pandas_bridge.slice_spiketrain(pdobj, t_start=None, t_stop=None)[source]

Slice a pandas.DataFrame, changing indices appropriately.

Values outside the sliced range are converted to NaN values.

Slicing happens over columns.

This sets the t_start and t_stop column indexes to be the new values. Otherwise it is the same as setting values outside the range to NaN.

Parameters:
pdobj : pandas DataFrame

The DataFrame to slice.

t_start : float, optional.

If specified, the returned DataFrame values less than this set to NaN. Default is None (do not use this argument).

t_stop : float, optional.

If specified, the returned DataFrame values greater than this set to NaN. Default is None (do not use this argument).

Returns:
pdobj : scalar, pandas Series, DataFrame, or Panel

The returned data type is the same as the type of pdobj

elephant.pandas_bridge.spiketrain_to_dataframe(spiketrain, parents=True, child_first=True)[source]

Convert a neo.SpikeTrain to a pandas.DataFrame.

The pandas.DataFrame object has a single column, with each element being the spike time converted to a float value in seconds.

The column heading is a pandas.MultiIndex with one index for each of the scalar attributes and annotations. The index is the spike number.

Parameters:
spiketrain : neo SpikeTrain

The SpikeTrain to convert.

parents : bool, optional

Also include attributes and annotations from parent neo objects (if any).

Returns:
pandas DataFrame

A DataFrame containing the spike times from spiketrain.

Notes

The index name is spike_number.

Attributes that contain non-scalar values are skipped. So are annotations or attributes containing a value of None.

quantity.Quantities types are incompatible with pandas, so attributes and annotations of that type are converted to a tuple where the first element is the scalar value and the second is the string representation of the units.