1

since .applymap() doesn't exist in Series, but in DataFrame, I'd like to keep my df['col'] as DataFrame.
I know that I could use .map() or .apply() [here a reference on topic]: Pandas: change data type of columns

But suppose I want to keep same methods name for code coherence... is there a way to force df['col'] to DataFrame ? AFAISI you could do :

pd.DataFrame(df['col']).applymap(isnan)

but it 2x slower than

df['col'].map(isnan)

that itself is FAR slower than

df['col'].apply(isnan)

is there no solution better than switching between .applymap and .apply() ?

Community
  • 1
  • 1
comte
  • 3,092
  • 5
  • 25
  • 41
  • 1
    A little unclear what you want, `applymap` is for a dataframe it doesn't make much sense to call `applymap` on a series when `apply` is specifically for this. You can get a df by using double square brackets: `pd.DataFrame(df[['col']]).applymap(isnan)` – EdChum Dec 02 '14 at 10:29
  • 1
    Maybe you want: `df[['col']].isnull()` ? – joris Dec 02 '14 at 10:46
  • what I'd would like was to use same function name for similar action on similar objects ! I still don't understand why we have Series.apply and DataFrame.applymap. But since I have huge respect for pandas devs (Wes in particuliar) I imagine there's a reason. Your answer (double square brackets 100% answers my question, thanks). – comte Dec 02 '14 at 12:54

0 Answers0