Created
December 8, 2017 08:42
-
-
Save porimol/57c1a10a0624166aa8aff0218d797d73 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import pandas as pd | |
data = pd.read_csv('test.csv') | |
# array3 = data['Column2'].replace(np.NaN,-1) | |
# length = array3.shape[0] | |
# print(length) | |
# arr3 = []; | |
# for i in range(length): | |
# if array3[i] != -1: | |
# # print(i) | |
# arr3.append(array[i]) | |
# | |
# print(arr3) | |
# trimmed = st.trim_mean(arr3,.05) | |
# mask=(data['Column1']=='Yes') & ((data['Column2'=='NA']) |(data['Column2'=='No']) | |
# data.loc[mask,'Column2']=pd.to_numeric(data['Column2'],errors='coerce').fillna(trimmed) | |
data['Column2'] = data['Column2'].fillna(data.apply(lambda cols: round(data['Column2'].mean(),2) if cols[0]=='yes' else -1, axis=1)) | |
data.to_csv(r'data.csv', index=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@PP227 have a look. I added here the solution with two sample output.
Sample Output 1
Sample Output 2