1

I am working with a dataframe loading from a CSV. Below is the link for the dataset: https://drive.google.com/open?id=1emA29M1lO3q-2YQOhegKRsAdlydBkgh6

I created a sample example for the same procedure. It worked. But when I tried with the data set, an error pops up as follow:

TypeError: ufunc 'multiply' did not contain a loop with signature matching
types dtype('<U32') dtype('<U32') dtype('<U32')

I am running random calculation for 10 times for each row in dataframe.

for i in range(len(WC2018_Fix.HomeTeam)):
    for j in range(0,10):
        TeamA = WC2018_Fix.iloc[i,0]
        TeamB = WC2018_Fix.iloc[i,1]
        ELO_1 = np.array(WC2018_Fix.iloc[i,2])
        ELO_2 = np.array(WC2018_Fix.iloc[i,3])
        ELOA  = random.random()*ELO_1
        ELOB  = random.random()*ELO_2

Can anyone advise what is going on?

9
  • 4
    Can you advise what are you trying to achieve? Sample input and output would be nice as well. Commented May 23, 2018 at 8:42
  • I tried with sample example but it worked... when I load the data frame it does not. Commented May 23, 2018 at 8:43
  • For the for loop, i will save the results for each loop in variables. but Current problem is error in the loop. Thanks @zipa Commented May 23, 2018 at 8:49
  • 1
    What is the problem? Any advise on the errors you are facing? Commented May 23, 2018 at 8:53
  • 3
    Have you googled your error message? stackoverflow.com/a/35016330/8881141 It seems you have strings, not float/integers in your dataframe. Commented May 23, 2018 at 8:55

1 Answer 1

1

In your loop, you can check the format/type of the values you read in. While multiplying if the expected cell value is not int/float you could type cast and then do it.

for i in range(len(WC2018_Fix.HomeTeam)):
    for j in range(0,10):
        TeamA = WC2018_Fix.iloc[i,0]
        TeamB = WC2018_Fix.iloc[i,1]
        if WC2018_Fix.iloc[i,2].__class__ == str:
          var = int(WC2018_Fix.iloc[i,2]) # Convert accordingly to int
        if WC2018_Fix.iloc[i,3].__class__ == str:
          var2 = int(WC2018_Fix.iloc[i,3])
        ELO_1 = np.array(var)
        ELO_2 = np.array(var2)
        ELOA  = random.random()*ELO_1
        ELOB  = random.random()*ELO_2
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.