They already explained this in the anime, one of the best times is in this episode --> https://www.dailymotion.com/video/x553h9e
Go to 21:40, episode: "Tree's is a crowd". Brock will explain why electric type moves aren't very effective against grass type Pokémon and have no effect on ground type Pokémon, and how they work normally on ground type Pokémon who are in the air like in the battle against Roxanne, when Pikachu's Thunder worked normally on Roxanne's Geodude.
Resume: Electric moves are weak against grass type Pokémon and have no effect on ground Pokémon because the electricity flows through the body of the Pokémon and disperse in the ground, tree, wall, etc. Like really happens with trees in the real world. That is why electric type moves aren't very effective against grass type Pokémon and have no effect on ground type Pokémon. However, Electric type moves work normal if the grass type and ground type Pokémon are not in contact with the ground or are soaked with water.