Python | Pandas Index.memory_usage ()
Python - отличный язык для анализа данных, в первую очередь из-за фантастической экосистемы пакетов Python, ориентированных на данные. Pandas - один из таких пакетов, который значительно упрощает импорт и анализ данных.
Pandas Index.memory_usage() function return the memory usage of the Index. It returns the sum of the memory used by all the individual labels present in the Index.
Syntax: Index.memory_usage(deep=False)
Parameters :
deep : Introspect the data deeply, interrogate object dtypes for system-level memory consumptionReturns : bytes used
Example #1: Use Index.memory_usage() function to find the overall memory used by the Index object.
# importing pandas as pdimport pandas as pd # Creating the Indexidx = pd.Index(["Labrador", "Beagle", "Mastiff", "Lhasa", "Husky", "Beagle"]) # Print the Indexidx |
Выход :
Now we will use Index.memory_usage() function to find the memory usage of the idx object.
# finding the memory used by the idx objectidx.memory_usage() |
Output :
The function has returned the value of 48 indicating that 48 bytes of memory are being used.
Example #2: Use Index.memory_usage() function to check the memory usage of the MultiIndex object.
# importing pandas as pdimport pandas as pd # Creating the MutiIndexmidx = pd.MultiIndex.from_arrays([["Mon", "Tue", "Wed", "Thr"], [10, 20, 30, 40]], names =("Days", "Target")) # Print the MultiIndexmidx |
Выход :
Now we will check the amount of memory used by the midx object.
# return the total memory used by the multi-index objectmidx.memory_usage() |
Выход :
Как видно из выходных данных, функция вернула 180, указывая, что объект midx использует 180 байт памяти.
Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.
Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.