Iterating through Pandas Column and replacing nan values Iterating through Pandas Column and replacing nan values pandas pandas

Iterating through Pandas Column and replacing nan values


You can use isnull() in something like:

df.loc[pd.isnull(df['A']), 'A'] = mylist

Example:

In [19]: dfOut[19]:      A  B      C0  7.2  b    woo1  NaN  v    sal2  NaN  o    sdd3  8.1  k  triliIn [20]: mylist = [3.2, 1.1]In [21]: df.loc[pd.isnull(df['A']), 'A'] = mylistIn [22]: dfOut[22]:      A  B      C0  7.2  b    woo1  3.2  v    sal2  1.1  o    sdd3  8.1  k  trili


n = iter([3.2, 1.1])for i, j in zip(*np.where(df.isnull())):    df.set_value(i, j, next(n), True)df     A  B      C0  7.2  b    woo1  3.2  v    sal2  1.1  o    sdd3  8.1  k  trili