Q:

Python - Defining a variable based on appearing more than one time within groups

I have the following data set and im trying to build a third variable by counting how many times a skill appear across the set, for example if they appear in group 1 three times we still count as one.I'm new to python and im not so sure where to start.
Group               Skill
  1                Windows
  1                Excel
  2                Windows                
  2                Java
  3                Windows
  3                Python
  4                Python
  4                SAS

What I am trying to achieve is, if a skill appear only in one group we call sector-specific, in more than one but less then 2 cross-sector and in more than 2 transversal. That may be times the same skill appear in the same group twice, however i still want to call only one time.
Then the final result would be:
Group               Skill               Type
  1                Windows            Transversal
  1                Excel              Sector-specific
  2                Windows            Transversal    
  2                Java               Sector-Specific
  3                Windows            Transversal
  3                Python             Cros-Sector
  4                Python             Cros-Sector
  4                SAS                Sector-specific

A:

First use SeriesGroupBy.nunique fot number of unique values per groups with transform for return Series with same size as original DataFrame and last map by dict, all unmatched values generate NaNs, so add fillna for replace it:
d = {1:'Sector-specific', 2:'Cros-Sector'}
df['Type'] = df.groupby('Skill')['Group'].transform('nunique').map(d).fillna('Transversal')
print (df)
   Group    Skill             Type
0      1  Windows      Transversal
1      1    Excel  Sector-specific
2      2  Windows      Transversal
3      2     Java  Sector-specific
4      3  Windows      Transversal
5      3   Python      Cros-Sector
6      4   Python      Cros-Sector
7      4      SAS  Sector-specific

Details:
print (df.groupby('Skill')['Group'].transform('nunique'))
0    3
1    1
2    3
3    1
4    3
5    2
6    2
7    1
Name: Group, dtype: int64

