Использование loc
для замены только там, где ViewersStart
не равно нулю:
df.loc[df.ViewersStart.notnull(),'ViewersStart'] = df.loc[df.ViewersStart.notnull(),'ViewersStart'].astype('int64')
Пример :
df = pd.DataFrame({'ViewersStart':['1','5',6,np.nan,'12']})
>>> df
ViewersStart
0 1
1 5
2 6
3 NaN
4 12
# Notice that your column is a mix of strings, ints and NaN
>>> df.values
array([['1'],
['5'],
[6],
[nan],
['12']], dtype=object)
df.loc[df.ViewersStart.notnull(),'ViewersStart'] = df.loc[df.ViewersStart.notnull(),'ViewersStart'].astype('int64')
>>> df
ViewersStart
0 1
1 5
2 6
3 NaN
4 12
# Notice that all non-null values are now ints
>>> df.values
array([[1],
[5],
[6],
[nan],
[12]], dtype=object)