info() method in pandas :Know dataframe info

info() method in pandas Know dataframe info

You can easily manipulate datasets once it is converted to dataframe. The Pandas module allows you to convert the datasets to dataframe using the pandas.DataFrame() constructor. But there is a case when you want to know quick information about the dataftame. You can get the information using the info() function. In this tutorial you will learn how to implement info() method in panda with various examples.

Syntax of the info() function

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

Here is the explanation of the main parameters.

verbose: It is of boolean type. Use it True when you want to get full information and false for less information.

buf : writable buffer, defaults to sys.stdout

memory_usage: Specifies whether total memory usage of the DataFrame elements (including the index) should be displayed.

show_counts: Whether to show the non-null counts.

null_counts: It is of boolean type

Examples of the implementation of info() method in pandas

Let’s know all the examples that you will implement here.

Example 1: Show the complete information about the dataframe

You can display the full information about the dataframe by passing the verbose =True as an argument of the info() function. You will get the following information.

1. class of the dataframe

2. number of rows and columns for the dataframe.

3.Type of the all columns

4. memory used by the dataframe.

5. Does column values contain null values or not?

Rub the below lines of code to get the information of the dataframe.

import pandas as pd
import numpy as np
data = {"name":["Rob","Bam","Maya","Rahul"],"age":[23,25,26,32],
"country":["USA","UK","France","Germany"]}
df = pd.DataFrame(data)
df.info(verbose=True)

Output

Example 2: Display less information about the dataframe

You can also see less information for your dataframe. But in this case, you have to pass the verbose =False as an argument of the info() function.

You will number of columns and rows, the type of column, and memory usage by the data frame.

Execute the below line of code.

import pandas as pd
import numpy as np
data = {"name":["Rob","Bam","Maya","Rahul"],"age":[23,25,26,32],
"country":["USA","UK","France","Germany"]}
df = pd.DataFrame(data)
df.info(verbose=False)

Output

displaying less information of the dataframe
displaying less information of the dataframe

Example 3: Display the information without null values

You can also get the information of the data frame without the null values. In this case, you have to pass the null_counts =False as the second parameter with verbose=True for the info() function.

You will get the following output when you will run the below lines of code.

import pandas as pd
import numpy as np
data = {"name":["Rob","Bam","Maya","Rahul"],"age":[23,25,26,32],
"country":["USA","UK","France","Germany"]}
df = pd.DataFrame(data)
df.info(verbose=True,null_counts=False)

Output

displaying the information without the null values
displaying the information without the null values

Conclusion

You can easily or quick information about the dataframe using the info() function. Thus it makes it very easy to know which columns are of type string or integer or float. In this post, you have learned how to display less or full information about the dataframe.

I hope you liked this tutorial. If you have any doubt about this pose you can contact us for more help.

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

Meet Sukesh ( Chief Editor ), a passionate and skilled Python programmer with a deep fascination for data science, NumPy, and Pandas. His journey in the world of coding began as a curious explorer and has evolved into a seasoned data enthusiast.
 
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner