Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何从For循环返回dataframe列值_Python 3.x_Pandas_Dataframe_For Loop_If Statement - Fatal编程技术网

Python 3.x 如何从For循环返回dataframe列值

Python 3.x 如何从For循环返回dataframe列值,python-3.x,pandas,dataframe,for-loop,if-statement,Python 3.x,Pandas,Dataframe,For Loop,If Statement,我正在尝试根据另一列的条目计算一列的值,我正在尝试使用for循环来实现这一点,我不知道如何返回整个列的值,而只是上一次迭代,下面是我的代码示例,请帮助我找出哪里做错了 def marks_calculation(Master_Sheet): for a in Master_Sheet.Marks Condition: if a == "Yes": Master_Sheet['Total'] = Master_Sheet['Tot

我正在尝试根据另一列的条目计算一列的值,我正在尝试使用for循环来实现这一点,我不知道如何返回整个列的值,而只是上一次迭代,下面是我的代码示例,请帮助我找出哪里做错了

def marks_calculation(Master_Sheet):
    for a in Master_Sheet.Marks Condition:
        if a == "Yes":
            Master_Sheet['Total'] = Master_Sheet['Total Marks']*0.85
            Master_Sheet.loc[(Master_Sheet['Total Marks'] > Master_Sheet['Basic1']) & (Master_Sheet['Total Marks'] <= Master_Sheet['Basic3']),'Total'] = (Master_Sheet['Basic1'] * Master_Sheet['Slab1']) + ((Master_Sheet['Total Marks'] - Master_Sheet['Basic1']) * Master_Sheet['Slab2'])
            Master_Sheet.loc[(Master_Sheet['Total Marks'] > Master_Sheet['Basic2']),'Total'] = (Master_Sheet['Basic1'] * Master_Sheet['Slab1']) + ((Master_Sheet['Basic2'] - Master_Sheet['Basic1']) * Master_Sheet['Slab2']) + ((Master_Sheet['Total Marks'] - Master_Sheet['Basic2']) * Master_Sheet['Slab3'])
            return Master_Sheet['Total']
        else :     
            Master_Sheet['Total'] = Master_Sheet['Aggregated Marks']
            return Master_Sheet['Total']
Master_Sheet['Total'] = Master_Sheet['Total'].replace("",0, regex=True)  
Master_Sheet[['Students','Total Marks','Aggregated Marks','Marks Condition','Total']]

这里,只有在条件为“是”时才需要计算总数,如果条件为“否”,则需要使用聚合中的数据。 如果条件为“是”,则总计的计算如下:


如果(TotalMarksBasic1,TotalMarks我无法理解计算示例,因此无法为“是”列生成内容。以下行将更新聚合数据列中的所有“总计”否条目

Master_Sheet['Total'].loc[Master_Sheet['Condition']=='No'] = Master_Sheet['Aggregated']

我无法理解计算示例,因此无法为“是”列生成某些内容。以下行将更新聚合数据列中的所有“总计”否条目

Master_Sheet['Total'].loc[Master_Sheet['Condition']=='No'] = Master_Sheet['Aggregated']

相关答案:我想坚持这个方法,为了可读性,np。where变得有点复杂,为了我的要求,我有什么办法可以让这个工作。相关答案:我想坚持这个方法,为了可读性,np。where变得有点复杂,为了我的要求,我有什么办法可以让它工作吗这是一项工作。