Created
September 7, 2020 15:36
-
-
Save tanpengshi/c395514e19fdf10eef8a690ffbf5d0f4 to your computer and use it in GitHub Desktop.
Replacing NaN with Mean of Values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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