DataFrames पर एडवांस्ड transformations लागू करना
pandas में कई built-in transformation टूल होते हैं, लेकिन कभी-कभी किसी transformation में और उन्नत लॉजिक की ज़रूरत पड़ती है। apply फंक्शन आपको किसी DataFrame की एक row या column पर user-defined function लागू करने देता है, जिससे एडवांस्ड transformation और feature generation के लिए रास्ता खुलता है.
find_street_name() फंक्शन "street_address" से street name पार्स करता है और string से street number हटा देता है। यह फंक्शन मेमोरी में लोड कर दिया गया है और raw_testing_scores DataFrame पर लागू करने के लिए तैयार है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में ETL और ELT
अभ्यास निर्देश
transform()फंक्शन की परिभाषा में,find_street_name()फंक्शन का उपयोग करके"street_name"नाम का नया कॉलम बनाएँ.transform()फंक्शन का उपयोग करकेraw_testing_scoresDataFrame को क्लीन करें.cleaned_testing_scoresDataFrame का head प्रिंट करें और नए"street_name"कॉलम को देखें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
def transform(raw_data):
# Use the apply function to extract the street_name from the street_address
raw_data["street_name"] = raw_data.____(
# Pass the correct function to the apply method
____,
axis=1
)
return raw_data
# Transform the raw_testing_scores DataFrame
cleaned_testing_scores = ____(raw_testing_scores)
# Print the head of the cleaned_testing_scores DataFrame
print(cleaned_testing_scores.____())