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?

Zephyr
  • 1,332
  • 2
  • 13
  • 31
  • 4
    Can you advise what are you trying to achieve? Sample input and output would be nice as well. – zipa May 23 '18 at 08:42
  • I tried with sample example but it worked... when I load the data frame it does not. – Zephyr May 23 '18 at 08: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 – Zephyr May 23 '18 at 08:49
  • 1
    What is the problem? Any advise on the errors you are facing? – Vivek Kalyanarangan May 23 '18 at 08:53
  • 3
    Have you googled your error message? https://stackoverflow.com/a/35016330/8881141 It seems you have strings, not float/integers in your dataframe. – Mr. T May 23 '18 at 08:55
  • In fact I did check the type as I thought types error. In this dataframe, only two columns”HomeTeam” and “away Team” are string. – Zephyr May 23 '18 at 09:07
  • But seemingly, ELO1 or ELO2 are strings. Have you printed out their data type in the loop? – Mr. T May 23 '18 at 09:13
  • I hv not. I will do it. Thanks – Zephyr May 23 '18 at 09:15
  • With the sample data provided and reading the dataframe with `WC2018_Fix = pd.read_csv("test.csv", sep = ",")`, I cannot reproduce your error. – Mr. T May 23 '18 at 09:18

1 Answers1

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
Surya Tej
  • 1,342
  • 2
  • 15
  • 25