繁星淼淼
您必须使用DataFrame.loc,对于按位置使用的列名称,请使用indexing by b.columns[2:6]。b = pd.DataFrame({'A':list('abaaef'), 'B':[4,5,4,5,5,4], 'C':[7,8,9,4,2,3], 'D':[1,3,5,7,1,0], 'E':[5,3,6,9,2,4]})print (b) A B C D E0 a 4 7 1 51 b 5 8 3 32 a 4 9 5 63 a 5 4 7 94 e 5 2 1 25 f 4 3 0 4b.loc[b["A"] == "a", b.columns[2:6]] = 100print (b) A B C D E0 a 4 100 100 1001 b 5 8 3 32 a 4 100 100 1003 a 5 100 100 1004 e 5 2 1 25 f 4 3 0 4