How to replace small values to zero in assembled matrix?

I would like to know if it is possible to replace the small values, for example lower than 1e-14, with zero? I am having spurious eigenvalues due to that small numbers.

I assemble the matrix as given below,

F  = derivative(Pi_ext, w, w_test)
J  = derivative(F_ext, w, w_trial)
asm    = SystemAssembler(J, F, bcs)

M = PETScMatrix()


I realized that my problem is not about small terms, and I think it is because of Lagrange elements.

In any case, I could replace the small values in the assembled matrix as given below,

M_dummy = M.array()
row1, col1 = numpy.nonzero((M_dummy < 1e-10) & (M_dummy > 1e-18))
row2, col2 = numpy.nonzero((M_dummy > -1e-10) & (M_dummy < -1e-18))
rlen1 = len(row1)
rlen2 = len(row2)
idx_row = numpy.zeros(1)
for i in range(rlen1):
    M.set(idx_row, numpy.array([row1[i]], dtype = numpy.uintc), numpy.array([col1[i]], dtype = numpy.uintc))

for i in range(rlen2):
    M.set(idx_row, numpy.array([row2[i]], dtype = numpy.uintc), numpy.array([col2[i]], dtype = numpy.uintc))