एक सेमी जॉइन करना
सबसे ज़्यादा रेवेन्यू लाने वाले कुछ ट्रैक्स TV-shows से हैं या फिर अन्य non-musical ऑडियो हैं। आपको invoices की एक टेबल दी गई है जिसमें top revenue-generating items शामिल हैं। इसके अलावा, आपके पास स्ट्रीमिंग सर्विस से non-musical ट्रैक्स की एक टेबल भी है। इस अभ्यास में, आप एक सेमी जॉइन का उपयोग करके top revenue-generating non-musical ट्रैक्स ढूँढेंगे.
टेबल्स non_mus_tcks, top_invoices, और genres आपके लिए लोड कर दी गई हैं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
pandas के साथ Data Joining
अभ्यास निर्देश
non_mus_tcksऔरtop_invoicesकोtidपर inner join से merge करें। नतीजाtracks_invoicesके रूप में सेव करें..isin()का उपयोग करकेnon_mus_tcksकी वे पंक्तियाँ चुनें जहाँtid,tracks_invoicesकीtidकॉलम में हो। नतीजाtop_tracksके रूप में सेव करें.top_tracksकोgidके आधार पर group करें औरtidपंक्तियों की गिनती करें। नतीजाcnt_by_gidमें सेव करें.cnt_by_gidकोgenresटेबल के साथgidपर merge करें और नतीजा प्रिंट करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Merge the non_mus_tcks and top_invoices tables on tid
tracks_invoices = ____.merge(____)
# Use .isin() to subset non_mus_tcks to rows with tid in tracks_invoices
top_tracks = _____[non_mus_tcks['tid'].isin(____)]
# Group the top_tracks by gid and count the tid rows
cnt_by_gid = top_tracks.groupby(['gid'], as_index=False).agg({'tid':____})
# Merge the genres table to cnt_by_gid on gid and print
print(____)