小编bre*_*sta的帖子

根据与其他列的相关性填充 pandas 数据框缺失的数据

error_text我有一个 pandas DataFrame,其中包含许多行和一列名为包含多个空值的字符串。我想根据该列与另一列的相关性来填充这些缺失的数据。

mydf_example = pd.DataFrame({'a':[1,2,3,4,5,6,3],'b':[10,20,30,40,50,60,30],'c':['a','b','c','d','e','f','c'], 'error_text':[np.nan,'some_text','other_text',np.nan,'more_text','another_text',np.nan]})
mydf_example

    a   b   c   error_text
0   1   10  a   NaN
1   2   20  b   some_text
2   3   30  c   other_text
3   4   40  d   Nan
4   5   50  e   more_text
5   6   60  f   another_text
6   3   30  c   NaN
Run Code Online (Sandbox Code Playgroud)

首先,我创建了sub_df删除丢失数据的行:

mydf_example = mydf_example.dropna()
mydf_example

    a   b   c   error_text
1   2   20  b   some_text
2   3   30  c   other_text
4   5   50  e   more_text
5   6   60  f   another_text
Run Code Online (Sandbox Code Playgroud)

然后我将该 …

python missing-data dataframe pandas

5
推荐指数
1
解决办法
226
查看次数

标签 统计

dataframe ×1

missing-data ×1

pandas ×1

python ×1