我遇到SettingWithCopyWarning
的问题,价值没有被替换。我在这个网站上进行了非常广泛的搜索,我在处理SettingWithCopyWarning
方面所看到的就是使用copy()
。但是,尝试使用col2中的值替换col1中的任何缺失值,即使使用以下代码也不适用于我 -
import numpy as np
import pandas as pd
import copy
test = pd.DataFrame({'a':[1,np.nan,3], 'b':[5,6,7]})
test2 = test.copy()
test3 = test.copy()
test2.loc[np.isnan(test2['a']) & (np.isnan(test2['b']) == False)]['a'] =
test3.loc[np.isnan(test3['a']) & (np.isnan(test3['b']) == False)]['b']
print(test2)
第一列中的NaN
仍然存在,我仍然获得SettingWithCopyWarning
。我错过了什么?
答案 0 :(得分:0)
我相信你需要:
public class FavoriteDto
{
public int EventId { get; set; }
}
编辑:
与public async Task<IActionResult> PostFavorite([FromBody] FavoriteDto favorite)
的解决方案非常相似,只是删除test = pd.DataFrame({'a':[1,np.nan,3], 'b':[5,6,7]})
test['a'] = test['a'].fillna(test['b'])
#alternative
#test['a'] = test['a'].combine_first(test['b'])
print (test)
a b
0 1.0 5
1 6.0 6
2 3.0 7
以避免chaining indexing:
loc