Reputation: 3765
I’m trying to figure out if it’s possible to achieve the following without using apply and without using a for loop.
df= [df[x].map(lambda x: len(x) > 5) for x in df.columns]
I’m specifically trying to avoid apply and applymap, and look for a vectorised solution. All values in DF are strings. I’m using the above as a mask later on.
The fastest I've found is:
df1 = [df[x].map(lambda x: len(x) > 5) for x in df.columns]
df2 = df[pd.concat(df1, axis=1, keys=[s.name for s in df1]).any(1)]
It's faster than:
df[(df.applymap(len) > 5).any(axis=1)]
Upvotes: 0
Views: 86