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)
然后我将该 …