Piezoelectric force microscopy (PFM) has demonstrated to be a powerful tool to characterize ferroelectric materials. However, extrinsic effects, most notably, those resulting from surface charges, often mask or mirror genuine piezoelectric response, challenging PFM data understanding. The contribution of surface charges to PFM signal is commonly compensated by using appropriate external bias voltage, which is ad-hoc selected and sample dependent. Here, we determine the compensating voltage in thin films of different ferroelectric materials and we compare with the corresponding I-V characteristics recorded using suitable electrodes. It turns out that the sign and magnitude of the bias voltage required to compensate the surface charges are related to the asymmetry of the I-V characteristics. We propose that this relation results from the fact that the semiconducting properties of the material determine both the I-V dependence, and the sign of charged adsorbates. We show how to make use of this correlation to predict the required compensation voltage of a non-ferroelectric material and we show that spurious piezoelectric-like contributions are largely cancelled. The results provide guidelines to mitigate common extrinsic contributions in PFM imaging.