Line magic function `%%time` not found

Chandrachud Pati picture Chandrachud Pati · Dec 3, 2020 · Viewed 14.6k times · Source

%%time

train_data = dt.fread('../input/prediction/train.csv').to_pandas()

The output results as an error and says UsageError: Line magic function %%time not found. Suggest some approach.

Answer

Simon Judd picture Simon Judd · Dec 9, 2020

%%time is a 'cell magic' and has to be the first thing in the IPython (Jupyter) cell. I can reproduce this error if for example I have a comment first. When %%time is not the first thing in the cell, IPython tries to interpret it as a 'line magic' hence the error you see.

I took a quick look in the documentation and it's not made explicitly clear there as far as I can see.