[英]Pandas Set multiple column and row values to nan based on another dataframe
I have two large dataframes, df1
:我有两个大数据
df1
:
Col1 Col2 Val1 Val2 Val3
asd ASYL 4.2 4.2
ppq CONE 35 35
DA HU 100 100
And df2
is df2
是
Col1 Col2 Val1 Val2 Val3
asd ASYL 7 12 17
ppq CONE 17 19 19
DA HU 5 14 13
Both dataframes have same index columns Col1
and Col2
and same value columns Val1, Val2, Val3
.两个数据框都有相同的索引列
Col1
和Col2
以及相同的值列Val1, Val2, Val3
。
I want to set the values in df2
to nan
where it is Null
in df1
to get the following:我想将
df2
中的值设置为nan
,其中df1
中的Null
得到以下信息:
Col1 Col2 Val1 Val2 Val3
asd ASYL 7 17
ppq CONE 19 19
DA HU 5 14
I tried the following:我尝试了以下方法:
idx = df1.isnull()
df2.loc[idx] = np.nan
But it is not working.但它不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.