El guardia and la guardia are both correct. One is a male guard and one is a female guard. Here is a case when the occupation looks to be one gender, but can be either, depending on the article that comes before it. Another example of when this happens is with "the journalist" -- it can be either "el periodista" or "la periodista", depending on if you are talking about a man or a woman. Also check out poeta, optometra, terapeuta, optimista, pesimista, artista, optometrista -- they all do the same thing.