3 ms·
import pandas as pd import functools ( pd.Series(range(10)) .apply(lambda x: x * 10) .where(lambda x: x % 2 == 0) .
by sampo 3y ago
import pandas as pd
import functools
(
pd.Series(range(10))
.apply(lambda x: x * 10)
.where(lambda x: x % 2 == 0)
.pipe(lambda s: functools.reduce(lambda x, y : x + y, s))
)
- melx 3y agoReadability isn't the best. Also what you present here is method chaining and not functional pipes.
- heyoni 3y agoIs the difference mostly syntactic?
- gnulinux 3y agoWhat difference does it make? They're conceptually the same thing. You're mapping immutable data to map/reduce/filter like pure functions to get new data.
- melx 3y agoImproved code readability. The pipe operator was a game changer for me even after 20 years of programming (I know I was probably touching wrong things).