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

Make index available to Series.map() lambda #325

Closed
brooksvb opened this issue Dec 24, 2021 · 2 comments
Closed

Make index available to Series.map() lambda #325

brooksvb opened this issue Dec 24, 2021 · 2 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@brooksvb
Copy link

Is your feature request related to a problem? Please describe.
The Series.map() function should enable the usage of index in the passed lambda, just like the normal Array.map() function does. My example use case is calculating a moving average, which requires referencing values next to the current position in the Series.

Describe the solution you'd like
I would like to be able to write this (which I initially tried to, and had to track down the reason it wasn't working, until I realized the internal map() just doesn't use or provide an index)

df[column].map((val, i) => {
	if (i < 5) return 'N/A'
	return df[column].iloc([`${i - 5}:${i}`]).mean()
})

Describe alternatives you've considered
The alternative option is to just get the actual Array object and use the Array.map() instead.

df[column].values.map((val, i) => {
	if (i < 5) return 'N/A'
	return df[column].iloc([`${i - 5}:${i}`]).mean()
})
@risenW
Copy link
Member

risenW commented Dec 27, 2021

Nice request, we will definitely add this. If interested you can work on this, just let me know.

@risenW risenW self-assigned this Dec 27, 2021
@risenW risenW added enhancement New feature or request good first issue Good for newcomers labels Dec 27, 2021
@risenW
Copy link
Member

risenW commented Jan 12, 2022

FIXED and released in the latest TS version.

If you need help migrating to the latest version, see: https://danfo.jsdata.org/examples/migrating-to-the-stable-version-of-danfo.js

@risenW risenW closed this as completed Jan 12, 2022
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

2 participants