Question:
i try to percentace missing value like thisnull_column = null[(null>= 10.0) & (null <= 40.0)].index [/code]
the output type is indexhow can i using fillna to replace median in every column based on index
my code before like this
null_column = null[(null>= 10.0) & (null <= 40.0)].index data.fillna(percent_column2.median(), inplace=True) [/code]
the result alwaysindex doesnt have median
but when i deleted index it works but the median that replaced is not median in every column. But, median that 2 values of percentage missing value not in original dataframe. How can i fill nan value based on index to replace in original data frame?
Answer:
I guess something like this:data = pd.DataFrame([[0,1,np.nan],[np.nan,1,np.nan],[1,np.nan,2],[23,12,3],[1,3,1]])
cols = list(null[(null>=10) & (null<=40)].index)
data.iloc[:, cols] = data.iloc[:, cols].fillna(data.iloc[:, cols].median(), inplace=False)
[/code]
If you have better answer, please add a comment about this, thank you!