President Carter yesterday granted clemency to Andrews Figueroa Cordero, one of four Puerto Rican nationalists serving prison terms for the 1954 shooting spree in the House of Representatives.

The White House said the President commuted Cordero's 25-to-75-year sentence on "humanitarian grounds" because Cordero is terminally ill with cancer.

Cordero, who has undergone three cancer operations, was released from a federal medical center for prisoners at Springfield, Ill., yesterday.

Cordero, imprisoned since 1954, would not have been eligible for parole until 1981. The three other terrorists with whom he was convicted remain in federal penitentiaries.

In the March 1, 1954, shooting incident, five congressmen who had just answered a quorum call on a farm bill fell wounded to the floor and about 100 others dove under their desks when the nationalists shouted "Freedom for Puerto Rico" and began spraying the chamber with bullets.

A group seeking Puerto Rican independence last year filed a lawsuit seeking Cordero's release and better treatment for the remaining nationalists convicted in that terrorist escapade, along with the release of a nationalist imprisoned for firing at President Truman's temporary residence at Blair House in 1950.

The White House stressed in a statement that Carter's order commuting Cordero's sentence to time already served was not a presidential pardon.