<jupyter_start><jupyter_text>Iteration speeds increased 10 times if we use iloc instead of treating it as array.<jupyter_code>len(G.edges)
len(G.nodes)
dc = nx.degree(G)
dc
#Adding new column clusteringCoeff
clusteringCoeff = []
for i in range(len(Glist)):
    egoGraph = nx.ego_graph(G,Glist[i],radius=1)
    clusteringCoeff.append(round(nx.average_clustering(egoGraph),2))
clusteringCoeff
dfDVD['CusteringCoeff'] = clusteringCoeff
dfDVD.head(10)
purchasedASIN = 'B00000IC8Z'
purchasedASINegoGraph = nx.ego_graph(G, purchasedASIN, radius=1)
purchasedASINegoGraph.edges
 purchasedASINegoGraph.edges(data=True)
threshold = 0.1
purchasedASIN_thresholdGraph = nx.Graph()
for node1,node2,info in purchasedASINegoGraph.edges(data=True):
    #print(node1,node2)
    #print(weight['weight'])
    if info['weight'] >= threshold:
        print(node2)
        purchasedASIN_thresholdGraph.add_edge(node1,node2,weight= info['weight'])

RecommendProducts = purchasedASIN_thresholdGraph.neighbors(purchasedASIN)
"""
final=[]
for product in tqdm(RecommendProducts):
    final.append(dfDVD.loc[ dfDVD['ASIN'] == product])
    print(dfDVD.loc[ dfDVD['ASIN'] == product])
"""
#len(final)<jupyter_output><empty_output><jupyter_text>Sort some products according to your criteria like any column or group of columns<jupyter_code>final[0]
dfFinal = pd.DataFrame(columns=dfDVD.columns)
dfFinal
dfDVD.head()
threshold = 0.4
purchasedASIN_thresholdGraph = nx.Graph()
for node1,node2,info in purchasedASINegoGraph.edges(data=True):
    #print(node1,node2)
    #print(weight['weight'])
    if info['weight'] >= threshold:
        print(node2)
        purchasedASIN_thresholdGraph.add_edge(node1,node2,weight= info['weight'])

RecommendProducts = purchasedASIN_thresholdGraph.neighbors(purchasedASIN)
RecommendProducts
i=0
for product in tqdm(RecommendProducts):
    temp = pd.DataFrame(dfDVD.loc[ dfDVD['ASIN'] == product].values)
    dfFinal.append(temp)
    i+=1
    print(dfDVD.loc[ dfDVD['ASIN'] == product].values)
dfFinal
#dfFinal.append([16,21,'0790747324','The Time Machine','DVD','0795B00007JMD8 6305350221 B00004RF9B B00005JKFR B0...','DVD Genres Drama General',140,4.55])
RecommendedProductsMetaData = []
for product in tqdm(RecommendProducts):
    row = dfDVD.loc[ dfDVD['ASIN'] == product].values
    ASIN = row[0][1]
    Title = row[0][2]
    SalesRank = row[0][4]
    TotalReviews = row[0][-3]
    AvgRating = row[0][-2]
    DegreeCentrality = dc[ASIN]
    ClusteringCoeff = row[0][-1]
    RecommendedProductsMetaData.append((ASIN,Title,SalesRank,TotalReviews,AvgRating,DegreeCentrality,ClusteringCoeff))
RecommendedProductsMetaData
recommendedProducts_byAvgRating_byTotalReviews = sorted(RecommendedProductsMetaData, key=lambda x: (x[4],x[3]), reverse=True)
recommendedProducts_byAvgRating_byTotalReviews
recommendedProducts_bySalesRank = sorted(RecommendedProductsMetaData, key=lambda x: (x[2]))
recommendedProducts_bySalesRank
recommendedProducts_byAvgRating_byTotalReviews_bySalesRank = sorted(sorted(RecommendedProductsMetaData ,key = lambda x : (x[2]), reverse=False), key= lambda x: (x[4],x[3]), reverse=True )
recommendedProducts_byAvgRating_byTotalReviews_bySalesRank<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12519561815336464, 'fraction_numerical': 0.032550860719874807, 'mean_word_length': 7.070707070707071, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '336468', 'license': 'MIT', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1135, 'n_words': 185, 'path': 'RecommendationModel.ipynb', 'repo_name': 'MITUL-SHAH/Co-purchasing-Products-Prediction', 'size': '3195'}