Skip to content
Advertisement

Replacing list comprehensions with pandas and numpy Python

The function below uses slices to get the maximum value between 2 indexes at once. So it gets the maximum value between 0 and 10 and then 10 and 12 and such. The function is derived from the answer to this post post. Is there a way I could could replace the list comprehensions in the form of a pandas function like pd.Series(). Or if possible do it as a numpy function.

JavaScript

Advertisement

Answer

I would recommend this:

JavaScript

output:

JavaScript

Another way that will NOT increase your performance and is merely a replacement for list comprehension in your answer (in fact, might even be slightly slower):

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement