I am new to pandas, I want to know that does pandas dataframe have their own way of exception handling other than using try/ except python.
I have tried exec function of python to write entire try/except in one line but I want pandas specific syntax or way of exception handling that can be done in a single line.
Below is the code that I have tried:
import pandas as pd
import numpy as np
data1 = {'id' : [1,2,3,4,5],
'Rate' : [5,9,3,'A',6],
'Name' : ['a','b','c','d','e']}
df = pd.DataFrame(data1)
df['M_Rate1'] = df['Rate'].apply(lambda x, y=exec("def f(s):\n try:\n return int(s) * 2\n except ValueError as e: return 'Only Number can be converted to int'"): f(x))
Is their a better way for exception handling in oneline in pandas?