我具有以下数据框,并希望将“ NaN”添加到“ DROP”列下的值“ 1”和“ 2”,并将相应的“ MEAN”列值也更改为“ NaN”。
print (df)
Flow DROP MEAN
0 1 0.0 0.025
1 2 NaN NaN
2 3 NaN NaN
3 4 0.0 0.020
之后:
protected async override void OnAppearing()
{
base.OnAppearing();
Task.Run(async () =>
{
await Task.Delay(TimeSpan.FromSeconds(10));
if (CrossConnectivity.Current.IsConnected)
{
//Some code here
Device.BeginInvokeOnMainThread(() =>
{
// If you need to update an UI element
});
}
});
}
答案 0 :(得分:1)
df.loc[df['DROP'].isin([1,2]), ['DROP','MEAN']] = np.nan
或通过比较不等于0
的值:
df.loc[df['DROP'] != 0, ['DROP','MEAN']] = np.nan
答案 1 :(得分:0)
您也可以使用np.where:
df['DROP'], df['MEAN'] = np.where(df.DROP != 0, np.nan, df['DROP']), np.where(df.DROP != 0, np.nan, df['MEAN'])
结果:
Flow DROP MEAN
0 1 0.0 0.025
1 2 NaN NaN
2 3 NaN NaN
3 4 0.0 0.020