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

पायथन - पैंडास इंडेक्स का नया व्यू बनाएं


पैंडास इंडेक्स का नया व्यू बनाने के लिए, index.view() मेथड का उपयोग करें। सबसे पहले, आवश्यक लाइब्रेरी इंपोर्ट करें:

import pandas as pd

पैंडास इंडेक्स बनाएं:

index = pd.Index([50, 10, 70, 110, 90, 50, 110, 90, 30])

पैंडास इंडेक्स प्रदर्शित करें:

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

एक नया व्यू बनाएं:

res = index.view('uint8')

नया व्यू प्रदर्शित करें:

print("\nThe new view...\n", res)

यह समान अंतर्निहित मान साझा करता है:

print("\nView for 0th index...\n", res[0])
print("\nView for 1st index...\n", res[1])

उदाहरण

import pandas as pd
# Creating Pandas index
index = pd.Index([50, 10, 70, 110, 90, 50, 110, 90, 30])
# 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)
# Create a new view
res = index.view('uint8')
# displaying the new view
print("\nThe new view...\n", res)
# shares the same underlying values
print("\nView for 0th index...\n", res[0])
print("\nView for 1st index...\n", res[1])

आउटपुट

Pandas Index... Int64Index([50, 10, 70, 110, 90, 50, 110, 90, 30], dtype='int64')
Number of elements in the index... 9
The dtype object... int64
The new view... [ 50 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 70 0 0 0 0 0 0 0 110 0 0 0 0 0 0 0 90 0 0 0 0 0 0 0 50 0 0 0 0 0 0 0 110 0 0 0 0 0 0 0 90 0 0 0 0 0 0 0 30 0 0 0 0 0 0 0]
View for 0th index... 50
View for 1st index... 0
  1. - पायथन - जांचें कि पैंडास इंडेक्स फ्लोटिंग टाइप का है या नहीं

    जांचने के लिए कि पैंडास इंडेक्स फ्लोटिंग टाइप का है या नहीं, पैंडास में index.is_floating() मेथड का उपयोग करें। सबसे पहले आवश्यक लाइब्रेरी इम्पोर्ट करें: import pandas as pd पैंडास इंडेक्स बनाएं: index = pd.Index([5.7, 6.8, 10.5, 20.4, 25.6, 30.8, 40.5, 50.2]) पैंडास इंडेक्स प्रदर्शित करें: print(Pa

  1. - पायथन पैंडास - अंतिम से पहले इंडेक्स पर नया इंडेक्स वैल्यू डालें

    अंतिम से पहले इंडेक्स पर नया इंडेक्स वैल्यू डालने के लिए index.insert() मेथड का उपयोग करें। अंतिम इंडेक्स वैल्यू -1 और डालने वाले वैल्यू को पैरामीटर के रूप में सेट करें। सबसे पहले आवश्यक लाइब्रेरी इम्पोर्ट करें: import pandas as pd पैंडास इंडेक्स बनाएं: index = pd.Index([Car,Bike,Airplane,Ship,Truck

  1. - पायथन - पैंडास डेटाफ्रेम में एक नया कॉलम बनाएं

    एक नया कॉलम बनाने के लिए, हम पहले से बने कॉलम का उपयोग करेंगे। पहले, आइए एक डेटाफ्रेम बनाएं और हमारी CSV पढ़ें: dataFrame = pd.read_csv(C:\\Users\\amit_\\Desktop\\SalesRecords.csv) अब, हम पहले से बने कॉलम Reg_Price से एक नया कॉलम New_Reg_Price बनाएंगे और प्रत्येक मान में 100 जोड़कर एक नया कॉलम बनाए