How To Get Memory Usages Of Each Columns In DataFrame?
Table Of Contents:
- Syntax To Get Memory Usages Of Data Frame.
- Examples Of Memory Usages.
(1) Syntax:
pandas.DataFrame.memory_usage
Description:
Return the memory usage of each column in bytes
Parameters:
- index: bool, default True – Specifies whether to include the memory usage of the DataFrame’s index in returned Series. If
index=True
, the memory usage of the index is the first item in the output. - deep: bool, default False- If True, introspect the data deeply by interrogating object dtypes for system-level memory consumption, and include it in the returned values.
Returns:
- Series: A Series whose index is the original column names and whose values is the memory usage of each column in bytes.
(2) Examples Of Memory Usages :
Example-1
import pandas as pd
student = {'Name':['Subrat','Abhispa','Arpita','Anuradha','Namita'],
'Roll_No':[100,101,102,103,104],
'Subject':['Math','English','Science','History','Commerce'],
'Mark':[95,88,76,73,93]}
student_object = pd.DataFrame(student)
student_object
Output:
student_object.memory_usage()
Output:
Index 128
Name 40
Roll_No 40
Subject 40
Mark 40
dtype: int64
Example-2
import pandas as pd
path = "E:\Blogs\Pandas\Documents\Mall_Customers.csv"
customer_details = pd.read_csv(path)
customer_details
Output:
customer_details.memory_usage()
Output:
Index 128
CustomerID 1600
Genre 1600
Age 1600
Annual_Income_(k$) 1600
Spending_Score 1600
date 1600
dtype: int64