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

DataFrame.diff/pct_change #383

Closed
joshuakoh1 opened this issue Feb 11, 2022 · 9 comments
Closed

DataFrame.diff/pct_change #383

joshuakoh1 opened this issue Feb 11, 2022 · 9 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@joshuakoh1
Copy link

joshuakoh1 commented Feb 11, 2022

There's no difference function?

https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.diff.html
https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.pct_change.html

@risenW risenW added enhancement New feature or request good first issue Good for newcomers labels Feb 15, 2022
@joshuakoh1
Copy link
Author

@risenW if this isn't a near term priority could you point me in the direction of how to hack together a difference operation? Which functions should I chain?

Thanks!

@risenW
Copy link
Member

risenW commented Feb 17, 2022

@risenW if this isn't a near term priority could you point me in the direction of how to hack together a difference operation? Which functions should I chain?

Thanks!

The might help https://ourcodeworld.com/articles/read/557/how-to-calculate-a-percentage-change-increase-and-decrease-from-2-values-in-javascript

@joshuakoh1
Copy link
Author

joshuakoh1 commented Feb 17, 2022

@risenW I mean how do I pass n, n-1 into the same function across the frame? I couldn't find anything that accesses the previous row

@risenW
Copy link
Member

risenW commented Feb 17, 2022

@risenW I mean how do I pass n, n-1 into the same function across the frame? I couldn't find anything that accesses the previous row

You need to write a custom function and then apply it to the DataFrame.
You can use the apply function to apply custom functions to rows or columns of a DataFrame. See https://danfo.jsdata.org/api-reference/dataframe/danfo.dataframe.apply.

@joshuakoh1
Copy link
Author

joshuakoh1 commented Feb 17, 2022

@risenW I'm not sure how to access the previous row. When I apply, I only get the current row but I would like a difference of the row above. df.apply only passes the same row.

keys = [A,B,C]
cols = [[1,2,3],[4,5,6],[7,8,9]]

I would like to diff B/C e.g. (5-2)/(6-3) then (8-5)/(9-6)

@NeonSpork
Copy link
Contributor

If nobody else is actively working on implementing those two functions, I can try my hand at making the equivalent function in danfo? :)

I may need a guiding hand writing tests however, though I'll do my best!

@risenW
Copy link
Member

risenW commented Feb 22, 2022

If nobody else is actively working on implementing those two functions, I can try my hand at making the equivalent function in danfo? :)

I may need a guiding hand writing tests however, though I'll do my best!

PR is definitely welcome! You can read the contributor guide here first: https://danfo.jsdata.org/contributing-guide If you need any help, just ping me in the PR

@risenW risenW assigned NeonSpork and unassigned steveoni Feb 22, 2022
@NeonSpork
Copy link
Contributor

I started digging into pandas, and essentially followed a rabbit hole further down into numpy. So this will likely take me a while, as there is a lot going on in the diff function!

It would appear that the best method of implementing the diff function is to emulate the numpy function which uses slice to isolate the relevant row/column and calculate the difference the python API for tensorflow essentially took that same numpy logic too.

Following that logic I can leverage the TensorflowJS method tf.slice() to achieve something similar. I've cloned and branched off, and will let you all know of any speedbumps or hiccups! Let me know if you have any thoughts or advice @risenW / @steveoni 🚀

@joshuakoh1
Copy link
Author

@NeonSpork thanks for the work. @risenW, any idea when is the next version bump featuring this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants