Finding Memory usage

Info() :

Info() methods return the summary of the dataframe. 

syntax: DataFrame.info(verbose=None, buf=None, max_cols=None, memory_usage=None, show_counts=None, null_counts=None)

This will print the short and sweet summary of the dataframe. It will also give the memory usage taken by the data frame when we mention it as the parameter. For the parameter, we should mention memory_usage as “deep”.  

Python3




import pandas as pd
 
 
df = pd.read_csv(data.csv)
df.info(memory_usage="deep")


Output:

Memory_usage():

Pandas memory_usage() function returns the memory usage of the Index. It returns the sum of the memory used by all the individual labels present in the Index.

Syntax: DataFrame.memory_usage(index=True, deep=False)

However, Info() only gives the overall memory used by the data. This function Returns the memory usage of each column in bytes. It can be a more efficient way to find which column uses more memory in the data frame.

Python3




import pandas as pd
 
df = pd.read_csv(data.csv)
df.memory_usage()


Output:

Pandas Memory Management

In this article, we will learn about Memory management in pandas.

When we work with pandas there is no doubt that you will always store the big data for better analysis. While dealing with the larger data, we should be more concerned about the memory that we use. There is no problem when you work with small datasets. It does not cause any issues. But we can program without dealing with memory issues in larger datasets.

Now we will see about how to reduce errors and memory consumption. It makes our work easier by speeding up the computation.

Similar Reads

Finding Memory usage

Info() :...

Ways to optimize  memory in Pandas

...