0

According to the following code pandas.DataFrame.apply, the first column is called twice. I wonder why this is happening and if there is a way to avoid it as the function might be an expensive function.

import pandas as pd

def func(x):
    print(x)
    return x*2
    
df = pd.DataFrame([[1,3,2], [5,1,4],[3,9,1]])
df2 = df.apply(func)
Eissa N.
  • 1,695
  • 11
  • 18
  • what is your pandas version? in 0.25 from docs: `Notes: In the current implementation apply calls func twice on the first column/row to decide whether it can take a fast or slow code path. This can lead to unexpected behavior if func has side-effects, as they will take effect twice for the first column/row.` – anky Jul 03 '20 at 17:47
  • I am using 0.24.1 – Eissa N. Jul 03 '20 at 17:54

0 Answers0