pythonpandasdataframe

How to check whether I'm in the last row when iterating using df.iterrows()?


How can I check whether I'm in the last row while iterating through rows using df.itterows()?

My code:

for index, row in df.iterrows():
...     # I want to check last row in df iterrows(). somelike row[0].tail(1)

Solution

  • Use

    for i, (index, row) in enumerate(df.iterrows()):
        if i == len(df) - 1:
            pass