Why does timeit take so long with pandas methods and how to time it?

52 Views Asked by At

I want to time a pandas method to compare with native python but it just hangs.

timeit("df.iloc[-1]", setup='import pandas as pd; df = pd.DataFrame([[1,1]])')

Why is this? And it there a way to use timeit with pandas?

Update: I also tried moving the setup outside the timit function as follows but it still takes a long time (38s)

import pandas as pd
df = pd.DataFrame([[1,1]])
timeit("df.iloc[-1]", globals=locals())
0

There are 0 best solutions below