How can I replace leading zeros with NAs? suppose I have the following example:
import pandas as pd
import numpy as np
df = pd.DataFrame(data={'c1': [0.0, 0.0, 1.0, 0.0], 'c2': [1.0, 1.0, 1.0, 0.0]})
the goal is to have the following result:
c1 c2
NA 1.0
NA 1.0
1.0 1.0
0.0 0.0
but doing the following will not work since it will replace all and not just the leading zeros:
df[np.abs(df) < 1e-50] = np.nan