Check what line caused the error with apply () (dataframe, Pandas)

When processing data with Pandas, I think that there are times when batch processing is performed using ʻapply ()`.

What to do when you want to find out what line was the error in the process of ʻapply ()`.

Assumed situation

df.Column name.apply(function name)
df['Column name'].apply(function name)

When an error is output with the above code.

solution

Use the generator to resolve which line caused the error.

def generater():
    x = 0
    while True:
        yield x
        x += 1

After that, add the following before and within the function definition.

g = generater() #add to
def function_name():

    print(g.__next__()) #add to

Recommended Posts

Check what line caused the error with apply () (dataframe, Pandas)
Check if the expected column exists in Pandas DataFrame
Calculate the time difference between two columns with Pandas DataFrame
Check the code with flake8
Extract the maximum value with pandas.
Bulk Insert Pandas DataFrame with psycopg2
I get an error with import pandas.
Plot the Nikkei Stock Average with pandas
Check the existence of the file with python
What is the cause of the following error?
Apply the error propagation formula to the standard error
Check the correlation with Kaggle's Titanic (kaggle③)
[Pandas] Expand the character string to DataFrame
Replace column names / values with pandas dataframe
Check the file size with du -sh *
Is there NaN in the pandas DataFrame?
Type conversion of multiple columns of pandas DataFrame with astype at the same time