Solution if consecutive years per company - first replace missing values by helper values - e.g. tmp, then use DataFrameGroupBy.shift and compare tmp.
Last set 0 by DataFrame.loc:
df = df.sort_values(['company', 'year'])
mask = df.assign(count=df['count'].fillna('tmp')).groupby('company')['count'].shift().eq('tmp')
df.loc[mask, 'weight'] = 0
print (df)
company year weight count
0 abc 2016 0.7 1.0
1 abc 2017 0.3 NaN
2 abc 2018 0.0 3.0
3 def 2015 0.6 6.0
4 def 2016 0.6 NaN
5 def 2017 0.0 7.0
6 def 2018 0.7 5.0
EDIT:
First add new years by reindex per groups with minimal and maximal years:
s = (df.set_index('year')
.groupby('company')['count']
.apply(lambda x: x.reindex(np.arange(x.index.min(), x.index.max() + 1)).fillna('tmp')))
print (s)
company year
abc 2016 1
2017 tmp
2018 3
def 2015 6
2016 8
2017 tmp
2018 5
Name: count, dtype: object
Then shift like in original solution per company, here by first level company and compare by tmp:
m = s.groupby(level=0).shift().eq('tmp').rename('m')
print (m)
company year
abc 2016 False
2017 False
2018 True
def 2015 False
2016 False
2017 False
2018 True
Name: m, dtype: bool
Create mask with same index like original DataFrame with join:
mask = df.join(m, on=['company','year'])['m']
print (mask)
0 False
1 False
2 True
3 False
4 False
5 True
Name: m, dtype: bool
Set 0 values:
df.loc[mask, 'weight'] = 0
print (df)
company year weight count
0 abc 2016 0.7 1.0
1 abc 2017 0.3 NaN
2 abc 2018 0.0 3.0
3 def 2015 0.6 6.0
4 def 2016 0.6 8.0
5 def 2018 0.0 5.0