Unsupported operand type(s) for +=: 'dict' and 'int'

Please help me identify where the issue is

Screen Link:

https://app.dataquest.io/m/350/guided-project%3A-profitable-app-profiles-for-the-app-store-and-google-play-markets/10/most-common-apps-by-genre-part-two![1|690x265]

My Code:

Replace this line with your code
```display_table(iOS_final, -5)

What I expected to happen:
Games : 58.16263190564867
Entertainment : 7.883302296710118
Photo & Video : 4.9658597144630665
Education : 3.662321539416512
Social Networking : 3.2898820608317814
Shopping : 2.60707635009311
Utilities : 2.5139664804469275

What actually happened: 

```TypeErrorTraceback (most recent call last)
<ipython-input-20-499f0c499886> in <module>()
----> 1 display_table(iOS_final, -5)

<ipython-input-19-7f990eb10d60> in display_table(dataset, index)
     19 
     20 def display_table(dataset, index):
---> 21     table = freq_table(dataset, index)
     22     table_display = []
     23     for key in table:

<ipython-input-19-7f990eb10d60> in freq_table(dataset, index)
      4 
      5     for row in dataset:
----> 6         table += 1
      7         value = row[index]
      8         if value in table:
Replace this line with the output/error
```TypeError: unsupported operand type(s) for +=: 'dict' and 'int'


<!--Enter other details below: -->

@essyaimee7,
The error is in line 6. from your code, table is a dictionary and as such it does not support the += operation.

The correct freq_table function should look like this:

def freq_table(dataset, index):
   table = {}
   total = 0
   
   for row in dataset:
       total += 1
       value = row[index]

       if value in table:
           table[value] += 1
       else:
           table[value] = 1

I hope this helps.

1 Like

yes, it has. Thanks for pointing that out

1 Like

@essyaimee7,

You’re welcome! If it solved your problem, would you mind marking the answer as solution? Thank you!

def freq_table(dataset,index):
dictionary={}
for app in dataset:
value=app[index]

    if value in dictionary:
        dictionary[value]+=1
    else:
        dictionary[value]=1
    proportion=dictionary[value]/len(dataset)
    percentage=proportion*100
    dictionary[value]=percentage
print(dictionary)

print(freq_table(free_apps_android,3))

I tried running your code but it is not providing the percentage value for the same.

Have you been able to troubleshoot it?

Got it. I was having indentation problem. Thanks buddy.

You are welcome buddy