GOAL: To turn my results that are in list format into a data frame that I can print. I have an index error, I tried to change the index numbers...but I don't think that is the underlying issue. Assistance would be much appreciated.
print(len(results)) #of lists
1072
print(results[0]) #First case to use for format
RelationRecord(items=frozenset({'Instant food products', 'hamburger meat'}),
support=0.003050330452465684, ordered_statistics=[OrderedStatistic(items_base=frozenset({'Instant
food products'}), items_add=frozenset({'hamburger meat'}), confidence=0.379746835443038,
lift=11.42143769597027)])
MY CODE:
results_w = []
for item in results:
pair = item[0]
items = [x for x in pair]
value0 = str(items[0])
value1 = str(items[1])
value2 = str(item[1])[:7]
value3 = str(item[2][0][2])[:7]
value4 = str(item[2][0][3])[:7]
rows = (value0, value1, value2, value3, value4)
results.append(rows)
lables = ['Item1','Item2','Support','Confidence','Lift']
Grocery_Pairings = pd.DataFrame.from_records(results, columns =lables)
print(Grocery_Pairings)
ERROR MESSAGE:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-34-9daa56933611> in <module>
9 value2 = str(item[1])[:7]
10
---> 11 value3 = str(item[2][0][2])[:7]
12 value4 = str(item[2][0][3])[:7]
13
IndexError: string index out of range
EXPECTED RESULT:
Item1 Item2 Support Confidence Lift
instant food products hamburger meat 0.00305 0.37974 11.4214