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

पायथन पांडा - पहले से बनाए गए इंडेक्स ऑब्जेक्ट के लिए इंडेक्स नाम सेट करें

पहले से बनाए गए इंडेक्स ऑब्जेक्ट के लिए इंडेक्स नाम सेट करने के लिए, index.set_names() . का उपयोग करें पंडों में विधि। सबसे पहले, आवश्यक पुस्तकालयों को आयात करें -

import pandas as pd

पांडा इंडेक्स बनाना -

index = pd.Index(["Electronics", "Mobile Phones", "Accessories", "Home Decor", "Books"])

पांडा सूचकांक प्रदर्शित करें -

print("Pandas Index...\n",index)

इंडेक्स का नाम सेट करें -

print("\nSet the index name...\n",index.set_names('Products'))

उदाहरण

निम्नलिखित कोड है -

import pandas as pd

# Creating Pandas index
index = pd.Index(["Electronics", "Mobile Phones", "Accessories", "Home Decor", "Books"])

# Display the Pandas index
print("Pandas Index...\n",index)

# Return the number of elements in the Index
print("\nNumber of elements in the index...\n",index.size)

# Return the dtype of the data
print("\nThe dtype object...\n",index.dtype)

# set the name of index
print("\nSet the index name...\n",index.set_names('Products'))

आउटपुट

यह निम्नलिखित आउटपुट उत्पन्न करेगा -

Pandas Index...
Index(['Electronics', 'Mobile Phones', 'Accessories', 'Home Decor', 'Books'], dtype='object')

Number of elements in the index...
5

The dtype object...
object

Set the index name...
Index(['Electronics', 'Mobile Phones', 'Accessories', 'Home Decor', 'Books'], dtype='object', name='Products')

  1. - पायथन पांडा - सूचकांक नाम बदलें

    अनुक्रमणिका का नाम बदलने के लिए, index.rename() . का उपयोग करें पंडों में विधि। सबसे पहले, आवश्यक पुस्तकालयों को आयात करें - import pandas as pd पांडा इंडेक्स बनाना - index = pd.Index(['Car','Bike','Airplane', 'Ship','Truck','Suburban'], name ='Tr

  1. - पायथन - जांचें कि क्या पंडों का सूचकांक वस्तु का है dtype

    यह जाँचने के लिए कि पंडों का सूचकांक वस्तु प्रकार का है या नहीं, index.is_object() का उपयोग करें तरीका। सबसे पहले, आवश्यक पुस्तकालयों को आयात करें - import pandas as pd पांडा इंडेक्स बनाना - index = pd.Index(["Electronics", 6, 10.5, "Accessories", 25.6, 30]) पांडा सूचकांक प्रद

  1. - कैसे अजगर पंडों में स्तंभ नाम से स्तंभ अनुक्रमणिका प्राप्त करने के लिए?

    पायथन पांडा में कॉलम नाम से कॉलम इंडेक्स प्राप्त करने के लिए, हम get_loc() . का उपयोग कर सकते हैं विधि। कदम - एक द्वि-आयामी, आकार-परिवर्तनीय, संभावित रूप से विषम सारणीबद्ध डेटा बनाएं, df । इनपुट डेटाफ़्रेम प्रिंट करें, df । df.columns . का उपयोग करके DataFrame के कॉलम ढूंढें । चरण 3 से कॉलम प्रिंट