Skip to content

Question about slicing a dataframe #253

Answered by Oggy16
Oggy16 asked this question in Q&A
Discussion options

You must be logged in to vote

During my tests I was able to reproduce the issue both with a separate dataframe and overwriting the existing one. While reading further through the docs, I found the "df.get_data_by_loc" function, which accepts Python style negative indexes.

As that pattern was familiar to me, I re-wrote the section as follows:

unsigned long df_size = df.get_column<float>("last").size();
if (df_size > (roll_period + 1)) {
    df = df.get_data_by_loc<std::string, float>(Index2D<long>{-(roll_period + 1), -1});
}

Not only does this look more familiar to me, my issue has also gone away. The sliding window works well and as I had expected, my performance has increased a lot after this change.

I am not sure w…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Oggy16
Comment options

@hosseinmoein
Comment options

@Oggy16
Comment options

Answer selected by Oggy16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
2 participants