标签:dataframe opp div lis imp array and 这一 .data
sklearn中的preprocessing下游imputer,可进官方文档参考。这里主讲pandas。
拿到数据,一般先检查是否有缺失值,用isnul()或notnull().
再决定dropna(),还是fillna()。
import pandas as pd
import numpy as np
df = pd.DataFrame({"col_1":[1, 2, 3, 666, 1480],
"col_2":[125, 999, 110, np.nan, 300],
"col_3":[1389, np.nan, np.nan, np.nan, 0]})
df
col_1 | col_2 | col_3 | |
---|---|---|---|
0 | 1 | 125.0 | 1389.0 |
1 | 2 | 999.0 | NaN |
2 | 3 | 110.0 | NaN |
3 | 666 | NaN | NaN |
4 | 1480 | 300.0 | 0.0 |
df.isnull() #询问每一个值是不是为NaN.
col_1 | col_2 | col_3 | |
---|---|---|---|
0 | False | False | False |
1 | False | False | True |
2 | False | False | True |
3 | False | True | True |
4 | False | False | False |
df.notnull() #询问每一个值是不是不为NaN,跟上面的相反就是了
col_1 | col_2 | col_3 | |
---|---|---|---|
0 | True | True | True |
1 | True | True | False |
2 | True | True | False |
3 | True | False | False |
4 | True | True | True |
考虑如何删,删行?删列?还是缺失多少个才删?
DataFrame.dropna(axis=0, how=‘any‘, thresh=None, subset=None, inplace=False)
df.dropna()
col_1 | col_2 | col_3 | |
---|---|---|---|
0 | 1 | 125.0 | 1389.0 |
4 | 1480 | 300.0 | 0.0 |
ing~~~
标签:dataframe opp div lis imp array and 这一 .data
原文地址:https://www.cnblogs.com/wyy1480/p/10486820.html