Skip to content

Instantly share code, notes, and snippets.

@tanpengshi
Created September 7, 2020 15:36
Show Gist options
  • Save tanpengshi/c395514e19fdf10eef8a690ffbf5d0f4 to your computer and use it in GitHub Desktop.
Save tanpengshi/c395514e19fdf10eef8a690ffbf5d0f4 to your computer and use it in GitHub Desktop.
Replacing NaN with Mean of Values
df['ENTRY_DELTA'][df['ENTRY_DELTA']>10000]=np.nan
df['ENTRY_DELTA'][df['ENTRY_DELTA']<0]=np.nan
# Setting the anomaly values due to reset of counters to the uniform NaN values
delta_list = list(df['ENTRY_DELTA'])
ind = 0
for i in delta_list:
if np.isnan(i) == 1:
delta_list[ind] = np.nanmean([delta_list[ind-1],delta_list[ind+1]])
ind += 1
df['ENTRY_DELTA_1'] = delta_list
# for each NaN values, replace it with the mean of values before and after the NaN value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment