समस्या विवरण
Series से उन तत्वों को चुनें जो 10 और 15 (सम्मिलित) के बीच हैं।
इनपुट Series
0 12 1 13 2 15 3 20 4 19 5 18 6 11 dtype: int64
अपेक्षित आउटपुट
0 12 1 13 2 15 6 11 dtype: int64
समाधान 1: between() विधि (सुझावित)
import pandas as pd
l = [12,13,15,20,19,18,11]
data = pd.Series(l)
result = data[data.between(10, 15)]
print("10 से 15 के बीच के तत्व:")
print(result)
समाधान 2: मैन्युअल लूप और isin()
import pandas as pd
l = [12,13,15,20,19,18,11]
data = pd.Series(l)
ls = []
for i in range(len(data)):
if data[i] >= 10 and data[i] <= 15:
ls.append(data[i])
print(data[data.isin(ls)])
आउटपुट (दोनों)
0 12 1 13 2 15 6 11 dtype: int64
नोट: between() डिफ़ॉल्ट रूप से दोनों सीमाओं को शामिल करता है। inclusive='neither' से अनन्य सीमाएँ कर सकते हैं।