इंडेक्स सेट करना और हटाना
pandas आपको कॉलम को एक index के रूप में निर्धारित करने देता है. इससे subsets लेते समय कोड साफ रहता है (और कुछ परिस्थितियों में lookup अधिक कुशल हो जाता है).
इस चैप्टर में, आप temperatures को एक्सप्लोर करेंगे, जो दुनिया भर के शहरों में औसत तापमान का एक DataFrame है. pandas pd के रूप में लोड किया गया है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
pandas के साथ Data Manipulation
अभ्यास निर्देश
temperaturesको देखें.temperaturesका इंडेक्स"city"पर सेट करें, और उसेtemperatures_indमें असाइन करें.temperatures_indको देखें. यहtemperaturesसे कैसे अलग है?temperatures_indका इंडेक्स रीसेट करें, और उसकी सामग्री को बनाए रखें.temperatures_indका इंडेक्स रीसेट करें, और उसकी सामग्री को ड्रॉप करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Look at temperatures
print(____)
# Set the index of temperatures to city
temperatures_ind = ____
# Look at temperatures_ind
print(____)
# Reset the temperatures_ind index, keeping its contents
print(____)
# Reset the temperatures_ind index, dropping its contents
print(____)