Time-stamped डेटा के लिए list comprehensions
अब आप इस चैप्टर से सीखी बातों का उपयोग करके एक सरल data extraction समस्या हल करेंगे. इस अभ्यास में आपको एक data structure, pandas की Series, से भी परिचित कराया जाएगा. हम यहाँ इस पर विस्तार से नहीं जाएँगे, लेकिन इतना जानना ज़रूरी है कि pandas DataFrames से डेटा विश्लेषण करते समय आप इसे अक्सर उपयोग करेंगे. आप DataFrame के कॉलम को single-dimension arrays मान सकते हैं, जिन्हें Series कहा जाता है.
इस अभ्यास में, आप time-stamped Twitter डेटा से time निकालने के लिए list comprehension का उपयोग करेंगे. pandas पैकेज pd नाम से इम्पोर्ट किया गया है और फ़ाइल 'tweets.csv' को आपके उपयोग के लिए df DataFrame के रूप में लोड किया गया है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python टूलबॉक्स
अभ्यास निर्देश
dfसे कॉलम'created_at'निकालें और परिणामtweet_timeको असाइन करें. मज़ेदार तथ्य:tweet_timeमें निकाला गया कॉलम एक Series data structure है!- एक list comprehension बनाएँ जो
tweet_timeकी हर row से time निकाले. हर row एक string होती है जो timestamp दर्शाती है, और आपको time निकालने के लिए string के 12th से 19th characters तक एक्सेस करना होगा. iterator variable के रूप मेंentryका उपयोग करें और परिणामtweet_clock_timeको असाइन करें. याद रखें कि Python 0-based indexing उपयोग करता है!
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Extract the created_at column from df: tweet_time
tweet_time = ____
# Extract the clock time: tweet_clock_time
tweet_clock_time = [____]
# Print the extracted times
print(tweet_clock_time)