Skip to content
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

query operator #623

Open
priyankat99 opened this issue Dec 26, 2023 · 1 comment
Open

query operator #623

priyankat99 opened this issue Dec 26, 2023 · 1 comment

Comments

@priyankat99
Copy link

i see querying by logical operators has been deprecated:
https://danfo.jsdata.org/api-reference/dataframe/danfo.dataframe.query#query-a-dataframe-using-logical-operators

is there a reason it was deprecated? i need to filter my DF to remove certain values like so:

 const filtered = this.datapoints.query({
        column: "ModelName",
        is: "==",
        to: "model"  
      }).query({
        column: "Timestamp",
        is: ">=",
        to: start  
      }).query({
        column: "Timestamp",
        is: "<=",
        to: end 
      }) 

was this logic deprecated because it is inefficient? im not sure how to achieve this with the updated logic in query.
any help or clarification would be appreciated!

@Xloka
Copy link

Xloka commented Mar 17, 2024

@priyankat99 you can't chain it but you can do this

const query = [
  {
    column: "ModelName",
    is: "==",
    to: "model"  
  },
  {
    column: "Timestamp",
    is: ">=",
    to: start  
  },
  {
    column: "Timestamp",
    is: "<=",
    to: end 
  }
];

const finalQuery = query.reduce((acc, condition, index) => {
  if (condition.is === '>=') {
    return index === 0 ? this.datapoints[condition.column].gte(condition.to) : acc.and(this.datapoints[condition.column].gte(condition.to));
  } else if (condition.is === '<=') {
    return index === 0 ? this.datapoints[condition.column].lte(condition.to) : acc.and(this.datapoints[condition.column].lte(condition.to));
  } else if (condition.is === '==') {
    return index === 0 ? this.datapoints[condition.column].eq(condition.to) : acc.and(this.datapoints[condition.column].eq(condition.to));
  }
}, null);

const filtered = this.datapoints.query(finalQuery);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants