Thursday, July 25, 2013

How to subset RPy2 dataframe

This example demonstrates how to create subsets of RPy2 data frames using single or multiple criteria. I also wanted to test if using Github Gist is a better way the display code snippets on this blog than using Bloggers formatting tools.

# By single criteria
subset_frame = dataframe.rx(dataframe.rx2('input_type').ro == 'VALUE', True)
# By Multiple Criteria
subset_frame = all_data_frame.rx((dataframe.rx2('input_type').ro == 'VALUE1').ro &
(dataframe.rx2('data_type').ro == 'VALUE2'), True)
And linked gist is here

No comments:

Post a Comment