import pandas as pd
df = pd.DataFrame([[1,2,3],[1,5,9],[2,1,5],[9,2,8]], index = [1,2,3], columns = ['A','B','C', 'D'])
假设我有一个像df这样的数据帧。 我想比较df中的所有行 如果df ['A']> df ['B']和df ['B']< df ['C']和df ['B']> df ['D'], 然后,如果为真,则df ['E'] ='是'或'否'为假。非常感谢
答案 0 :(得分:0)
您的数据帧不可重现,请检查错误。我在这里创建了一个类似的数据帧。
Classes = dict()
Classes["FALL14"] = ("ENGR","156","01",'Engineering 3'),("ENGR","156","01",'Engineering 4'),("SCI","156","01",'Chemistry 1'),("ENGL","156","01",'Writing 1')
Classes['SPRING15'] =("ENGL","156","01",'Writing 2'),("MATH","156","01",'Calculus 1'),("MATH","156","01",'Calculus 2'),("MATH","156","01",'Calculus 3')
Classes['FALL15'] =("MATH","156","01",'Differential Equations'),("ENGR","156","01",'Solid Works'),("ENGR","156","01",'MATLAB'),("ENGR","156","01",'Dynamics')
Classes['SPRING16'] = ("ENGR","156","01",'Statics'),("ART","156","01",'Drawing 1'),("ENGR","156","01",'Fluid Dynamics'),("ENGR","156","01",'Thermodynamics 1')
for semester, information in Classes.items():
for classes in information:
if 'ENGR' in classes:
print classes
您可以像这样添加E列:
df = pd.DataFrame({'A': [1,2,10], 'B': [1,5,5], 'C': [2,1,7], 'D': [9,2,4]})
它提供了所需的输出。