10000 Make index available to Series.map() lambda · Issue #325 · javascriptdata/danfojs · GitHub
[go: up one dir, main page]

Skip to content
Make 9574 index available to Series.map() lambda #325
Closed
@brooksvb

Description

@brooksvb

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()
})

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0