Screen Link:
My Code:
tag_count = pd.DataFrame(columns=["used", "viewed"])
tag_count["viewed"] = tag_count["viewed"].astype(int)
for index,row in questions.iterrows():
for row in row["Tags"]:
if tag in tag_count.index:
tag_count.loc[tag, "used"] += 1
tag_count.loc[tag, "viewed"] += row["ViewCount"]
else:
tag_count.loc[tag, "used"] = 1
tag_count.loc[tag, "viewed"] = row["ViewCount"]
I was trying to combine used counts and viewed counts into one dataframe at the same time but I’m getting this error and I’m not really sure why:
TypeErrorTraceback (most recent call last)
<ipython-input-35-9a21ba05fd3b> in <module>()
9 else:
10 tag_count.loc[tag, "used"] = 1
---> 11 tag_count.loc[tag, "viewed"] = row["ViewCount"]
TypeError: string indices must be integers
So I try to change row["ViewCount"]
to row[3]
but I get this error instead:
<ipython-input-13-2cfb8596892d> in <module>()
6 if tag in tag_count.index:
7 tag_count.loc[tag, "used"] += 1
----> 8 tag_count.loc[tag, "viewed"] += row[3]
9 else:
10 tag_count.loc[tag, "used"] = 1
IndexError: string index out of range
Any ideas? Thank you!