Skip to content
Advertisement

How to print the current row number when using .apply on DataFrame

I’ve seen this question for R, but not for python.

Basically, I have a large DataFrame where I apply a function row-wise. It takes a very long time to run and I hoped to put a print statement to show where I am. I put together an example of what I would like to do.

I know an alternative, but I wondered if possible with apply.

So this would work fine

JavaScript

Output

JavaScript

But I hoped to do something with apply such as:

JavaScript

Many thanks.

Advertisement

Answer

I guess you can write your function like this:

JavaScript

The usage is following:

JavaScript
Advertisement