-
Notifications
You must be signed in to change notification settings - Fork 302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add to_dataframe() to Record. #380
Conversation
3e87b0f
to
8c820d9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wfdb/io/record.py
Outdated
) | ||
|
||
return pd.DataFrame( | ||
data=self.p_signal, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be an option to set data to different signal types, e.g. d_signal
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps; I added a variable check to support all 4 combinations of data. I'm not sure if it makes sense for digital data though so I'll let someone else decide whether we want to keep it.
It doesn't seem very efficient to store a regularly sampled signal as a dataframe. What's the use-case for this? To filter samples based on a datetime range? Perhaps it wold be better to add methods that get you the first index of the signal before, after, or between datetimes, which would incidentally solve for the d_signal/p_signal issue mentioned above. Let me know if the dataframe is more useful for other reasons. |
Maybe not efficient, but lots of people are familiar with Pandas DataFrames which is good for accessibility. This small chunk of code allows people to quickly play around with the data in a familiar structure. e.g. perhaps not a great example of a use case, but I could do something like: View the data: import wfdb
import matplotlib.pyplot as plt
import seaborn as sns
record = wfdb.rdrecord('sample-data/a103l')
df = record.to_dataframe()
df.head()
II V PLETH
0 days 00:00:00 -0.023596 0.867586 0.482203
0 days 00:00:00.004000 -0.036981 0.982985 0.544374
0 days 00:00:00.008000 -0.062923 0.859791 0.478212
0 days 00:00:00.012000 -0.092452 0.788783 0.442857
0 days 00:00:00.016000 -0.094522 0.851996 0.474302 Plot the distribution of measurements: sns.boxplot(data=df)
plt.show() |
Ok, makes sense. @Ivorforce can you please add a unit test and an example in the demo notebook? |
38d3679
to
88af056
Compare
Yes, sorry for not providing motivation - @tompollard got it exactly right. I opened this PR for accessibility to new people and compatibility to existing libraries. Editing an ipython notebook is a bit of a struggle if you don't want to change metadata, but I added a unittest and a demo like asked. I also added support for digital and expanded signals. Let me know if it's ready like this. |
This looks nice! I don't really use Pandas so I don't have much to add here. One question that comes to mind: is there a way for the dataframe to indicate the physical units of each channel/column? |
No support for units in dataframes. See this issue: pandas-dev/pandas#10349 |
88af056
to
53fc6e6
Compare
53fc6e6
to
7a88b44
Compare
I switched to |
7a88b44
to
b97c579
Compare
@Ivorforce it looks like one of the tests is failing. Please could you take a look when you have time? See: https://github.com/MIT-LCP/wfdb-python/runs/6904057193?check_suite_focus=true
|
b97c579
to
34365eb
Compare
Whoops, looks like I missed this. Tests should pass now. |
Ty! |
Convenient for a quick start with records.