Javaexercise.com

How To Find The Installed Pandas Version in python

A DataFrame is the primary data structure of the Pandas library in Python and is commonly used for storing and working with tabular data.

A common operation that could be performed using Pandas is to find its installed version on our system to make debugging and referring documentation easier. 

To start working with Pandas, we first need to import it:

import pandas as pd

Now, let’s say we need to find the installed version of Pandas on our system. The resulting output would look like this (output depends on your version of pandas) :

1.3.5

Let us look at different ways of performing this operation on a given DataFrame:

Find Pandas Version using the pd.__version__ property in Python

In this method, we use the pd.__version__ property to find the installed version of pandas on our system.

The returned value is stored in a variable named ver and this value is later printed.

In this example, the version was 1.3.5 which is seen in the output but this might change based on the version of pandas currently installed on your system.

Let us take a look at the corresponding code snippet and generated output for this method:

# Importing pandas
import pandas as pd

# Getting the version
ver = pd.__version__

# Printing the version
print(ver)

Output:

1.3.5

Find Pandas version using the pip command

In this method, we use the pip command to find the installed version of pandas on our system.

This command needs to be run in the command prompt.

We use pip list to list all the libraries currently installed and then use the piping | operator with the grep command to filter out the pandas library.

In this example, the version was 1.3.5 which is seen in the output but this might change based on the version of pandas currently installed on your system.

Let us take a look at the corresponding code snippet and generated output for this method:

pip list | grep pandas

Output : 

1.3.5

Find Pandas Version using the pd.show_versions() function

In this method, we use the pd.show_versions() function to find the installed version of pandas on our system.

We pass the parameter as_json as False in this example.

In this example, the version was 1.3.5 which is seen in the output but this might change based on the version of pandas currently installed on your system.

Along with the version of pandas, we get the versions of other dependencies as well.

Let us take a look at the corresponding code snippet and generated output for this method:

# Importing pandas
import pandas as pd

# Printing version
pd.show_versions(as_json = False)

Output : 

pandas           : 1.3.5

Conclusion

In this topic, we have learned to find the installed version of Pandas DataFrame on our system. Feel free to reach out to [email protected] in case of any suggestions.