pandas实际开发中进行运算时的一个坑!
import pandas as pd v = {'value': 'a'} d = [{'name': 'abc', 'age': 10}, {'name': None, 'age': 11}, {'name': 'def', 'age': 9}] df = pd.DataFrame(d) new_1 = df[(df['age'] >= 10) | df['name'].str.contains(v['value'])] new_2 = df[df['name'].str.contains(v['value']) | (df['age'] >= 10)] print('-'*80) print(df) print('-'*80) print(new_1) print('-'*80) print(new_2)
输出
-------------------------------------------------------------------------------- age name0 10 abc1 11 None2 9 def-------------------------------------------------------------------------------- age name0 10 abc1 11 None-------------------------------------------------------------------------------- age name0 10 abc
想请问为什么 new1 和 new2的结果不一样?
慕仙森
相关分类