Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
compare and modify columns in dataframe
#1
Hello all,

I'm have loaded a csv file into a dataframe using pandas. I want to compare the numbers in two columns, if col A is the same as col b, do this. If Col a is > col b, do this. and so on.

I'm pretty sure there is a shorter way to do this. Here is my code:

Thanks!!

for index,row in puntos.iterrows():

    if row["localGoals"] > row["visitorGoals"]:        
        puntos["PuntosLocal"] = 3
        puntos["PuntosVisitante"] = 0
        print(row["localGoals"])
    elif row["localGoals"] < row["visitorGoals"]:
        puntos['PuntosLocal'] = 0
        puntos['PuntosVisitante'] = 3
    else:
        puntos['PuntosLocal'] = 1
        puntos['PuntosVisitante'] = 1
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to format text to modify itself for different console sizes. FWendeburg 0 30 Feb-18-2019, 06:43 PM
Last Post: FWendeburg
  Convert row data to columns based on keyword mjack24 1 36 Feb-18-2019, 06:39 PM
Last Post: micseydel
  loop to compare lists KHas 1 71 Jan-31-2019, 10:17 PM
Last Post: Larz60+
  Compare words Python xSphere 3 124 Jan-24-2019, 10:52 AM
Last Post: perfringo
  How to compare string Rehan11 3 151 Jan-19-2019, 03:03 PM
Last Post: Rehan11
  How to compare different UV spectrum profiles SriRajesh 2 116 Jan-19-2019, 08:52 AM
Last Post: SriRajesh
  how to modify moth_ws for different coins danmcg 4 132 Jan-16-2019, 07:06 PM
Last Post: danmcg
  modify line in file if pattern found in list. kttan 1 158 Dec-10-2018, 08:45 AM
Last Post: Gribouillis
  How to find common names in multiple columns SriRajesh 3 223 Nov-27-2018, 07:30 PM
Last Post: ichabod801
  Print data in rows and columns rlinux57 5 314 Nov-10-2018, 05:50 AM
Last Post: rlinux57

Forum Jump:


Users browsing this thread: 1 Guest(s)