सबको जोड़कर लिंक करें!
पिछले लेसन में, आपने restaurants और restaurants_new को लिंक करने के अपने काम का बड़ा हिस्सा पूरा कर लिया था. आपने संभावित मिलान वाली पंक्तियों के अलग-अलग pair बनाए, cuisine_type और city कॉलम में exact matches ढूँढे, और rest_name कॉलम में similar strings की तुलना की. स्कोर वाला DataFrame आपने potential_matches में सेव किया था.
अब आखिरकार दोनों DataFrames को लिंक करने का समय है. सबसे पहले आप potential_matches से ऊपर बताए गए कॉलमों में मिलान हो रही restaurants_new की सभी row indices निकालेंगे. फिर आप इन्हीं indices पर restaurants_new को subset करेंगे, और अंत में non-duplicate मानों को restaurants के साथ concatenate करेंगे. सभी DataFrames आपके environment में हैं, और pandas को pd नाम से इम्पोर्ट किया गया है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में डेटा क्लीनिंग
अभ्यास निर्देश
.sum()मेथड का उपयोग करकेpotential_matchesके वे इंस्टेंस अलग कीजिए जिनका row sum 3 से अधिक या बराबर हो..get_level_values()मेथड का उपयोग करकेmatchesसे दूसरा कॉलम इंडेक्स निकालिए, जोrestaurants_newमें matching record की row indices दर्शाता है.restaurants_newको उन पंक्तियों के लिए subset कीजिए जोmatching_indicesमें नहीं हैं.restaurantsऔरnon_dupको concatenate कीजिए.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Isolate potential matches with row sum >=3
matches = ____[____.___(____) >= ____]
# Get values of second column index of matches
matching_indices = matches.____.____(____)
# Subset restaurants_new based on non-duplicate values
non_dup = ____[~restaurants_new.index.____(____)]
# Concatenate restaurants and non_dup
full_restaurants = pd.____([____, ____])
print(full_restaurants)