If you are using the latest version of pandas, you should be able to divide by 0. I can run your code without getting a division by zero error.
If for some reason you are using a version of pandas that doesn't support division by 0, and cannot upgrade pandas for this particular problem, you can get around this error by using numpy.inf whenever df['value2']
= 0, and calculating the percentage normally otherwise:
import pandas as pd
import numpy as np
df = pd.DataFrame({'value1':[4,5,2,0.1],'value2':[8,7,0,0]})
df["percent"] = df.apply(lambda x: x['value1']/x['value2'] if x['value2'] != 0 else np.inf, axis=1)
Result:
>>> df
value1 value2 percent
0 4.0 8 0.500000
1 5.0 7 0.714286
2 2.0 0 inf
3 0.1 0 inf