'pandas- label firm panel

I have a panel of firms, and I want to do the following. Based on some conditions, I want to create a column with labels for each firm. See an example:

enter image description here

I want for each different firmid, if RDCAP is nan for all of the year range, to be classified as an EXP or else as a CAP. The issue is, that when I try to do this, it classifies firms as EXP if for a single year they have RDCAP equal to nan.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source