Your experience isn't unusual; I suspect many of us have found our minds wandering occasionally when we pray. Sometimes, I know, I've been praying about a particular problem, and suddenly realized I was thinking about the problem instead of actually praying about it.
You can be sure, however, that the devil doesn't want us to pray, and he'll do anything he can to keep us from prayer. Do you remember Jesus' final hours just before His arrest and trial? Almost the last thing He did was go to an isolated area to pray. He took three of His closest disciples with Him and three times He found them asleep. His words to them apply to us all: "Watch and pray so that you will not fall into temptation. The spirit is willing, but the body is weak" (Mark 14:38).
How can you keep your mind from wandering when you pray? First, remember what you are doing: talking to God. If you had an opportunity to talk with the president, I doubt if your mind would wander. But you and I have the privilege of talking to someone far greater: the King of kings and the Lord of lords!
Then prepare for your times of prayer. Many find it helpful to keep a list of those for whom you are praying. You may find it helpful also to pray aloud; your mind will be less likely to wander. Include also times of thanksgiving and praise. When our focus is on God instead of ourselves, our minds won't wander.