pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 0
I think this error comes from your [i]
notation, which is trying to look for the DataFrame index value of 0, which doesn't exist. Try replacing every instance of [i]
with .iloc[i]
.
Also, you should be able to replace the for loop with much more compact, readable, and less error-prone code, especially since you define emotion_map
but use it only for output. Try changing the mapping from strings to integers with emotion_map = { 0:6, 1:3, 2:4, 3:5, 4:2, 5:1, 6:0}
, then move it to just under filtered_csv = ...
, and replace that for
loop with
filtered_csv['expression'] = filtered_csv['expression'].replace(emotion_map)
Pandas Dataframe should always be used with iloc as it does not support to indexing with 0. I faced the same issue when there was only single element & I was trying to access that single element by prefixing 0......