The book of Acts begins with Jesus telling his followers to remain in Jerusalem and wait until they are baptized with the Holy Spirit. After he gave his final commands he was taken up into Heaven. The promised baptism occurred in chapter two. Between these two events Peter felt the need to take care of some unfinished business, choosing a replacement for Judas.
In those days Peter stood up among the brothers (the company of persons was in all about 120) and said, “Brothers, the Scripture had to be fulfilled, which the Holy Spirit spoke beforehand by the mouth of David concerning Judas, who became a guide to those who arrested Jesus.
It is written in the Book of Psalms,
‘May his camp become desolate,
and let there be no one to dwell in it’;
and ‘Let another take his office.’
So one of the men who have accompanied us during all the time that the Lord Jesus went in and out among us, beginning from the baptism of John until the day when he was taken up from us—one of these men must become with us a witness to his resurrection.”
Acts 1:15-16; 20-22