pythonanaconda

Comparing 2 Columns to determin if higher or lower


trying to Compare 2 Columns lag2open to MGC=F and return if it is higher and returning it as Higher than 0

using GCClose["Higher than 0"] = [GCClose.columns[1]]>= [GCClose.columns[0]] it always returns True, while the validation column diff doesn't support that idea

Anyone can Explain to me what i am doing wrong? Example


Solution

  • If I understand your intention:

    GCClose.columns[1] is the NAME of the column not its contents (try printing it)

    You could use either:

     = GCClose[GCClose.columns[1]] >= GCClose[GCClose.columns[0]]
    

    or

     = GCClose.iloc[:,1] >= GCClose.iloc[:,0]
    

    or simplest

     = GCClose['lag2Open'] >= GCClose['MGC=F']