我试图替换数据框中的某些数据,以包含附加的“F”。你知道吗
代码应如下所示:
if testdata['pfType'] =='NK225M'|testdata['pfType'] == 'TOPIXM':
testdata['pfType'] = ' testdata['pfType'] & 'F';
我试着这么做:
testdata['pfType'][testdata['pfType'] == 'NK225M'] = 'NK225MF'
testdata['pfType'][testdata['pfType'] == 'TOPIXM'] = 'TOPIXMF'
但它不会改变值,如果是NK225M或TOPIXM,那么向字符串中添加“F”的最佳方法是什么。你知道吗
使用^{} 作为列表的测试值,如果匹配条件添加
F
:具有^{} 或^{} 的其他解决方案:
使用
np.where
使用
numpy.where
例如:
输出:
相关问题 更多 >
编程相关推荐