Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> Python

Python Pandas में DateTimeIndex में विशिष्ट दिन के समय के बीच मानों के इंडेक्स स्थान लौटाएं

DateTimeIndex में दिन के विशिष्ट समय के बीच मानों के इंडेक्स स्थान लौटाने के लिए DateTimeIndex.indexer_between_time() मेथड का उपयोग करें।

आवश्यक लाइब्रेरी आयात करें

import pandas as pd

DatetimeIndex बनाएं

पीरियड 5 और आवृत्ति T यानी मिनट के साथ DatetimeIndex बनाएं। टाइमज़ोन Australia/Adelaide है।

datetimeindex = pd.date_range('2021-10-30 02:30:50', periods=5, tz='Australia/Adelaide', freq='20T')

DateTimeIndex प्रदर्शित करें

print("DateTimeIndex...\n", datetimeindex)

दिन के विशिष्ट समय के बीच मानों के इंडेक्स स्थान प्रदर्शित करें

"start_time" '02:30:50' पर सेट है और "end_time" '03:20:50'।

print("\nIndex locations of values between particular time of day...\n", datetimeindex.indexer_between_time('02:30:50', '03:20:50'))

पूरा उदाहरण

import pandas as pd

# DatetimeIndex with period 5 and frequency as T i.e. minutes
# The timezone is Australia/Adelaide
datetimeindex = pd.date_range('2021-10-30 02:30:50', periods=5, tz='Australia/Adelaide', freq='20T')

# display DateTimeIndex
print("DateTimeIndex...\n", datetimeindex)

# display DateTimeIndex frequency
print("\nDateTimeIndex frequency...\n", datetimeindex.freq)

# display index locations of values at particular time of day i.e. 03:10:50 here
print("\nIndex locations of values at particular time of day...\n", datetimeindex.indexer_at_time('2021-10-30 03:10:50'))

# display index locations of values between particular time of day
# The "start_time" is set '02:30:50' and "end_time" '03:20:50'
print("\nIndex locations of values between particular time of day...\n", datetimeindex.indexer_between_time('02:30:50', '03:20:50'))

आउटपुट

DateTimeIndex... DatetimeIndex(['2021-10-30 02:30:50+10:30', '2021-10-30 02:50:50+10:30', '2021-10-30 03:10:50+10:30', '2021-10-30 03:30:50+10:30', '2021-10-30 03:50:50+10:30'], dtype='datetime64[ns, Australia/Adelaide]', freq='20T')
DateTimeIndex frequency... <20 * Minutes>
Index locations of values at particular time of day... [2]
Index locations of values between particular time of day... [0 1 2]
  1. - Python Pandas - इंडेक्स द्वारा चयनित मानों का नया इंडेक्स लौटाएं

    परिचय निर्दिष्ट इंडेक्स (स्थितियों) द्वारा चयनित मानों का नया इंडेक्स प्राप्त करने के लिए index.take() मेथड का उपयोग करें। आवश्यक लाइब्रेरी आयात करें import pandas as pd पैंडास इंडेक्स बनाएं index = pd.Index([Electronics, Accessories, Decor, Books, Toys], name=Products) पैंडास इंडेक्स प्रदर्शित क

  1. - पायथन पैंडास - UTC दिन और समय दर्शाने वाला नया टाइमस्टैम्प लौटाएं

    UTC दिन और समय दर्शाने वाला नया टाइमस्टैम्प लौटाने के लिए timestamp.utcnow() मेथड का उपयोग करें। सबसे पहले आवश्यक लाइब्रेरी इम्पोर्ट करें: import pandas as pd टाइमस्टैम्प बनाएं: timestamp = pd.Timestamp(2021-10-16T15:12:34.261811624, tz=UTC) UTC दिन और समय के साथ नया टाइमस्टैम्प: timestamp.utcnow()

  1. - पायथन पैंडास में दो इंडेक्स मानों के बीच डेटाफ्रेम पंक्तियाँ चुनें

    हम दो इंडेक्स मानों के बीच पंक्तियों का चयन करने के लिए पैंडास डेटाफ्रेम को स्लाइस कर सकते हैं। आइए एक उदाहरण लें और देखें कि यह कैसे किया जाता है। चरण दो-आयामी, आकार-परिवर्तनीय, संभावित विषम सारणीबद्ध डेटा, df बनाएं। इनपुट डेटाफ्रेम, df प्रिंट करें। इंडेक्स की निचली सीमा के लिए एक वेरिएबल इनिशियल