President Carter ended his seven-day vacation on the Mississippi River today and headed for Camp David for a rest.

He should need it. During his 659 mile steamboat trip, he made 58 speeches, an average of one every three hours, day and night. He stopped at 47 cities, hamlets and river locks, often in the wee hours of the morning. He shook thousands of hands, sometimes in the driving rain.

It was, he told the crowd gathered under this city's Gateway Arch, "the most remarkable and enjoyable week of our lives."

White House aides judged the trip an unqualified success for Carter, whose popularity in the polls is at an all-time low. His welcome in the five Midwest states he passed was generally warm and enthusiastic.

Only in St. Louis, the largest city he visited, did he encounter the grim realities of urban politics.

The turnout was disappointingly small, as fewer than 10,000 of the 100,000 people that Mayor Jim Conway had predicted would greet the president showed up. Among them were several hundred demonstrators protesting Carter's energy and anti-inflation policies and his failure to nominate a Missouri woman for a federal judgeship. Some were angry about the closing of a city-owned hospital in a predominately black area.

"Windfall no; price control," they changed as Carter pleaded: "Work with me and the U.S. Congress to overcome the oil lobby."

"We live in the greatest nation on earth," Carter said later, repeating the standard speech he made at every stop.

Officially, the trip was a "working vacation" designed to promote the president's energy proposals. Unofficially, it was a thinly disguised campaign shakedown cruise reminiscent of a whistle-stop campaign tour, except Carter was speaking from the side of a steamboat instead of from the rear of a railroad car.

Carter told reporters aboard the Delta Queen Thursday night the trip might give some clues to the kind of reelection campaign he'll wage in 1980, if he decides to run.

The trip cost taxpayers tens of thousands of dollars. Scores of Secret Service agents and Coast Guard officers were on hand to protect the president. Several dozen White House press, logistics and communications aides were flown or driven from stop to stop, many of them returning to a St. Louis motel each night.

Carter paid $1,960 for himself and Rosalynn to ride on the Delta Queen. Daughter Amy, like the other children on board, rode free. But the White House rang up a tab of almost $11,000 for the week on the sternwheeler, about a fourth of which will be paid by news organizations that had reporters making the trip.

The trip may have been more than the Carters originally bargained for. "We thought we would only have four stops," Mrs. Carter said last night in the chat with reporters. "That's what the schedule showed."

But when it became clear that the sight of a president and a steamboat was an irresistible draw in the small towns along the Mississippi, the Carters plunged. Whenever a crowd appeared, Carter stopped to talk and shake hands.

Many, if not most, of the people who came out were not Carter supporters. They were simply people who wanted to see a president of the United States float by, and they were willing to spend hours waiting in the rain to do so.

"We never had crowds like this as a candidate," Mrs. Carter said.

When Carter was called on to address the captain's dinner on the Delta Queen last night, the president took special pains to apologize to his fellow 150 passengers for "our early-morning and late-night speeches and calliope playing."

Carter's last night on board was typical of the week. At 11:15 p.m., he gave a speech at Lock 25 at Windfield, Mo. At 4:15 a.m., he was up again, this time shaking hands at lock and dam 26 near Alton, Ill., promising to build a new lock there.

"You need some rest," one woman told the president. "I'm going to get some right now," he replied.

But he left a wakeup call with Vic Tooker, who plays the boat's calliope along with 17 other instruments and doubles as the Delta Queen chaplain. At 6:45 a.m., strains of "Oh, How I Hate to Get Up in the Morning," blasted across the sundeck, waking the Carters and most other people aboard.

The White House advance team had worked for days arranging a grand finale rally in St. Louis. When the steamboat moved within a quarter-mile of the landmark Gateway Arch, it was joined by a parade of local tugs and boats. Fireworks exploded in the sky. Firemen shot water into the air, and a red, yellow and purple hot-air balloon soared with the words "Hellow Jimmy" written on its side.

Professionally painted Carter signs were planted on the hillside. And one woman waved a placard that said, "I'm a Libra. I also read the newspaper in the bathroom. You're okay; I'm okay." This was a reference to Carter's statement earlier this week that he gets much of his reading done at the dinner table and in the bathroom.

After a reception with local political leaders. Carter flew back to Washington this afternoon. He swore in Charles Duncan as the new secretary of energy, then left for Camp David, where he plans to say until Wednesday or Thursday.