DC Components and Frequency
how do you even measure the frequency of a digital signal?


This may be the source of your confusion. In digital communications, data is transmitted using an analog, continuous-time waveform. This is necessary because only this kind of waveform can exist in the physical world. Like all waveforms, it has a bandwidth, and its Fourier Transform determines what frequencies are present in it.

In digital communications, the waveform used to communicate has a specific form: it is a sequence of pulses, and the amplitude of the pulses encodes the transmitted bits.

The simplest waveform is one that encodes a bit $1$ with a pulse of positive amplitude, and a bit $0$ with a pulse of equal but negative amplitude. You may think that, for random bits, the negative pulses cancel out with the positive pulses and the average DC level of the signal is 0. This is in general not true over short time periods; even random bits will have sequences with many more $1$'s than $0$'s, or viceversa. This differential causes the signal's DC to grow, which causes distortion at the receiver end.

Line encoding can help with this problem. For example, the Alternate Mark Inversion line code encodes a bit $0$ to a pulse of amplitude zero, and a bit $1$ to pulses of positive and negative amplitude, alternating. So, every positive pulse is followed by a negative pulse, and the signal's DC never builds up.