Open In App

How to Fix: No module named pandas

Last Updated : 19 Dec, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will discuss how to fix the No module named pandas error.

The error “No module named pandas ” will occur when there is no pandas library in your environment IE the pandas module is either not installed or there is an issue while downloading the module right.

Let’s see the error by creating an pandas dataframe.

Example: Produce the error

Python3




# import pandas
import pandas
  
# create dataframe
pandas.DataFrame({'a': [1, 2]})


Output:

We will discuss how to overcome this error. In python, we will use pip function to install any module

Syntax:

pip install module_name

So we have to specify pandas

Example: Installing Pandas 

Python3




pip install pandas


Output:

Collecting pandas

  Downloading pandas-3.2.0.tar.gz (281.3 MB)

     |████████████████████████████████| 281.3 MB 9.7 kB/s 

Collecting py4j==0.10.9.2

  Downloading py4j-0.10.9.2-py2.py3-none-any.whl (198 kB)

     |████████████████████████████████| 198 kB 52.8 MB/s 

Building wheels for collected packages: pandas

  Building wheel for pandas (setup.py) … done

  Created wheel for pandas: filename=pyspark-3.2.0-py2.py3-none-any.whl size=281805912 sha256=c6c9edb963f9a25f31d11d88374ce3be6b3c73ac73ac467ef40b51b5f4eca737

  Stored in directory: /root/.cache/pip/wheels/0b/de/d2/9be5d59d7331c6c2a7c1b6d1a4f463ce107332b1ecd4e80718

Successfully built pandas

Installing collected packages: py4j, pandas

Successfully installed py4j-0.10.9.2 pandas-3.2.0

We can verify by again typing same command then the output will be:

Output:

Requirement already satisfied: pandas in /usr/local/lib/python3.7/dist-packages (1.1.5)

To get the pandas description in our environment we can use the show command. This can help keep track of the module and its installation.

Example: Show module description 

Python3




# display pandas details
pip show pandas


Output:

Name: pandas

Version: 1.1.5

Summary: Powerful data structures for data analysis, time series, and statistics

Home-page: https://pandas.pydata.org

Author: None

Author-email: None

License: BSD

Location: /usr/local/lib/python3.7/dist-packages

Requires: numpy, python-dateutil, pytz

Required-by: xarray, vega-datasets, statsmodels, sklearn-pandas, seaborn, pymc3, plotnine, pandas-profiling, pandas-gbq, pandas-datareader, mlxtend, mizani, holoviews, gspread-dataframe, google-colab, fix-yahoo-finance, fbprophet, fastai, cufflinks, cmdstanpy, arviz, altair

Upgrade Pandas

Upgrading pandas is the best advantage to get error-free in your environment. So, we have to upgrade using the following command.

Example: Upgrading Pandas

Python3




pip3 install pandas - -upgrade


Output:

Install Specific version

To install a specific version of pandas we have to specify the version in the pip command.

Example: Installing a specific version of a module

Python3




# install 1.3.4 version
pip3 install pandas == 1.3.4


Output:

Find the version

If we want to find the version then we have to use __version__

Syntax:

module_name.__version__

Example: Get pandas version

Python3




#import module
import pandas as pd
  
# get the version
pd.__version__


Output:

1.1.5


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads