flight_data is dataframe in panda:
for c in flight_data.columns:
if ('Delay' in c):
flight_data[c].fillna(0, inplace = True)
How do I do this in 1 line using lambda function?
map(lambda c: flight_data[c].fillna(0, inplace = True), list(filter(lambda c : 'Delay' in c, flight_data.columns)))
Why aren't these two equivalent?
When printing out the data, NaN is not replaced by 0.
mapproduces, only the side effect of calling thefillnamethod on each element of the original sequence. Keep theforloop as it is.map; until then, you just have a bunch of method calls waiting to happen.mapeffectively just creates a wrapper around the original iterable. When you retrieve an element from it, you pull an element from the original "through" the function being mapped over it. Only then does the function actually get called. By contrast, in Python 2,mapimmediately called the function on each element of the iterable, return a list of the return values.