परिचय
पैंडास इंडेक्स में डेटा का प्रतिनिधित्व करने वाली नम्पाई सरणी (numpy array) प्राप्त करने के लिए index.values प्रॉपर्टी का उपयोग करें।
आवश्यक लाइब्रेरी आयात करें
import pandas as pd
इंडेक्स बनाएं
index = pd.Index(['Car', 'Bike', 'Truck', 'Ship', 'Airplane'])
इंडेक्स प्रदर्शित करें
print("पैंडास इंडेक्स...\n", index)
सरणी प्राप्त करें
print("\nसरणी...\n", index.values)
पूर्ण उदाहरण
import pandas as pd
# इंडेक्स बनाएं
index = pd.Index(['Car', 'Bike', 'Truck', 'Ship', 'Airplane'])
# इंडेक्स प्रदर्शित करें
print("पैंडास इंडेक्स...\n", index)
# इंडेक्स में डेटा का प्रतिनिधित्व करने वाली सरणी लौटाएं
print("\nसरणी...\n", index.values)
# इंडेक्स का ट्रांसपोज़ प्रदर्शित करें
print("\nपैंडास इंडेक्स का ट्रांसपोज़...\n", index.T)
आउटपुट
पैंडास इंडेक्स... Index(['Car', 'Bike', 'Truck', 'Ship', 'Airplane'], dtype='object') सरणी... ['Car' 'Bike' 'Truck' 'Ship' 'Airplane'] पैंडास इंडेक्स का ट्रांसपोज़... Index(['Car', 'Bike', 'Truck', 'Ship', 'Airplane'], dtype='object')
मुख्य बिंदु
index.valuesअंतर्निहित नम्पाई सरणी (np.ndarray) लौटाता है।- यह इंडेक्स डेटा का व्यू हो सकता है (कॉपी नहीं)।
- संशोधन से बचें क्योंकि यह इंडेक्स को प्रभावित कर सकता है।
- सुरक्षित कॉपी के लिए
index.values.copy()याnp.array(index)का उपयोग करें।