Screen Link: Learn data science with Python and R projects
So, here I already have a tags dataframe that contains single Tags as indexes and the n of times they were used as a column.
Now I am trying to add the amount of views for each of those tags directly as a column to the tags dataframe. But there seems to be a mistake somewhere
tags['views'] = 0 for tag in tags: for row in questions: if tag in row: tags.loc[tag]['views'] += questions.loc[row]['ViewCount'] else: tags.loc[tag]['views'] = tags.loc[tag]['views']
What I expected to happen:
A nice “views” column with the sum of views for each tag.
What actually happened:
KeyError Traceback (most recent call last) /opt/anaconda3/lib/python3.8/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance) 3079 try: -> 3080 return self._engine.get_loc(casted_key) 3081 except KeyError as err: #<more error info here> KeyError: 'count'
I understand there must be some mess with the .loc indices but I am not sure what to google to find out what it is. Please, help.