शुरू करेंमुफ़्त में शुरू करें

स्ट्रिंग से नंबर निकालना

UFO डेटासेट में length_of_time फ़ील्ड एक टेक्स्ट फ़ील्ड है जिसमें मिनटों की संख्या स्ट्रिंग के भीतर होती है. यहाँ, आप रेग्युलर एक्सप्रेशन का उपयोग करके उस टेक्स्ट फ़ील्ड से वह संख्या निकालेंगे.

यह अभ्यास पाठ्यक्रम का हिस्सा है

Python में Machine Learning के लिए Preprocessing

पाठ्यक्रम देखें

अभ्यास निर्देश

  • time_string में नंबर खोजने के लिए उपयुक्त RegEx पैटर्न का उपयोग करें.
  • .apply() मेथड का उपयोग करके length_of_time कॉलम की हर पंक्ति पर return_minutes() कॉल करें.
  • तुलना के लिए length_of_time और minutes दोनों कॉलम का .head() प्रिंट करें.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

def return_minutes(time_string):

    # Search for numbers in time_string
    num = re.____(____, ____)
    if num is not None:
        return int(num.group(0))
        
# Apply the extraction to the length_of_time column
ufo["minutes"] = ufo["length_of_time"].____

# Take a look at the head of both of the columns
print(ufo[[____]].head())
कोड संपादित करें और चलाएँ