你可以用
apply与
list comprehension:
df1['A'] = df1['A'].apply(lambda x: [y if y <= 9 else 11 for y in x])print (df1) A2017-01-01 02:00:00 [11, 11, 11]2017-01-01 03:00:00 [3, 11, 9]
更快的解决方案是先转换为
numpyarray,然后使用
numpy.where:
a = np.array(df1['A'].values.tolist())print (a)[[33 34 39] [ 3 43 9]]df1['A'] = np.where(a > 9, 11, a).tolist()print (df1) A2017-01-01 02:00:00 [11, 11, 11]2017-01-01 03:00:00 [3, 11, 9]
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)