Skip to content

Commit 8c820d9

Browse files
committed
Add to_dataframe() to Record.
1 parent 0d42dfb commit 8c820d9

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

wfdb/io/record.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,35 @@ def _arrange_fields(self, channels, sampfrom, smooth_frames):
851851
# Adjust date and time if necessary
852852
self._adjust_datetime(sampfrom=sampfrom)
853853

854+
def to_dataframe(self) -> pd.DataFrame:
855+
"""
856+
Create a dataframe containing the same data as the record.
857+
858+
859+
Returns
860+
-------
861+
A dataframe, with sig_name in the columns. The index is a DatetimeIndex
862+
if both base_date and base_time were set, otherwise a TimedeltaIndex.
863+
"""
864+
if self.base_datetime is not None:
865+
index = pd.date_range(
866+
start=self.base_datetime,
867+
periods=self.sig_len,
868+
freq=datetime.timedelta(seconds=1 / self.fs),
869+
)
870+
else:
871+
index = pd.timedelta_range(
872+
start=datetime.timedelta(),
873+
periods=self.sig_len,
874+
freq=datetime.timedelta(seconds=1 / self.fs),
875+
)
876+
877+
return pd.DataFrame(
878+
data=self.p_signal,
879+
index=index,
880+
columns=self.sig_name
881+
)
882+
854883

855884
class MultiRecord(BaseRecord, _header.MultiHeaderMixin):
856885
"""

0 commit comments

Comments
 (0)