def count(self, level=None):
if level is None:<EOL><INDENT>return notna(com.values_from_object(self)).sum()<EOL><DEDENT>if isinstance(level, str):<EOL><INDENT>level = self.index._get_level_number(level)<EOL><DEDENT>lev = self.index.levels[level]<EOL>level_codes = np.array(self.index.codes[level], subok=False, copy=True)<EOL>mask = level_codes == -<NUM_LIT:1><EOL>if mask.any():<EOL><INDENT>level_codes[mask] = cnt = len(lev)<EOL>lev = lev.insert(cnt, lev._na_value)<EOL><DEDENT>obs = level_codes[notna(self.values)]<EOL>out = np.bincount(obs, minlength=len(lev) or None)<EOL>return self._constructor(out, index=lev,<EOL>dtype='<STR_LIT>').__finalize__(self)<EOL>
Return number of non-NA/null observations in the Series.

Parameters
----------
level : int or level name, default None
    If the axis is a MultiIndex (hierarchical), count along a
    particular level, collapsing into a smaller Series.

Returns
-------
int or Series (if level specified)
    Number of non-null values in the Series.

Examples
--------
>>> s = pd.Series([0.0, 1.0, np.nan])
>>> s.count()
2