मान लीजिए, आपके पास एक डेटाफ्रेम है और न्यूनतम और अधिकतम थ्रेशहोल्ड मान ट्रिम करने का परिणाम है,
minimum threshold: Column1 Column2 0 30 30 1 34 30 2 56 30 3 78 50 4 30 90 maximum threshold: Column1 Column2 0 12 23 1 34 30 2 50 25 3 50 50 4 28 50 clipped dataframe is: Column1 Column2 0 30 30 1 34 30 2 50 30 3 50 50 4 30 50
समाधान
इसे हल करने के लिए, हम नीचे दिए गए चरणों का पालन करेंगे −
एक डेटाफ्रेम परिभाषित करें
न्यूनतम थ्रेशहोल्ड मान की गणना करने के लिए df.clip फंक्शन को (lower=30) के अंदर लागू करें,
df.clip(lower=30)
अधिकतम थ्रेशहोल्ड मान की गणना करने के लिए df.clip फंक्शन को (upper=50) के अंदर लागू करें
df.clip(upper=50)
न्यूनतम और अधिकतम थ्रेशहोल्ड सीमा के साथ क्लिप्ड डेटाफ्रेम लागू करें,
df.clip(lower=30,upper=50)
उदाहरण
बेहतर समझ के लिए निम्नलिखित कोड देखें −
import pandas as pd data = {"Column1":[12,34,56,78,28], "Column2":[23,30,25,50,90]} df = pd.DataFrame(data) print("DataFrame is:\n",df) print("minimum threshold:\n",df.clip(lower=30)) print("maximum threshold:\n",df.clip(upper=50)) print("clipped dataframe is:\n",df.clip(lower=30,upper=50))
आउटपुट
DataFrame is: Column1 Column2 0 12 23 1 34 30 2 56 25 3 78 50 4 28 90 minimum threshold: Column1 Column2 0 30 30 1 34 30 2 56 30 3 78 50 4 30 90 maximum threshold: Column1 Column2 0 12 23 1 34 30 2 50 25 3 50 50 4 28 50 clipped dataframe is: Column1 Column2 0 30 30 1 34 30 2 50 30 3 50 50 4 30 50