Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named 'pandas'

Tags:

python

pandas

I am trying to learn pandas and I haven't been able to import it into my code.

I have looked at other answers on this site and none of them have worked.

I just installed anaconda and installed everything through conda.

Here is a sample script that I am trying to run.

import pandas as pd

writer = pd.ExcelWriter('farm_data.xlsx', engine='xlsxwriter')
df.to_excel(writer, sheet_name='Sheet1')

workbook = writer.book
worksheet = writer.sheets['Sheet1']

chart = workbook.add_chart({'type': 'column'})

And the error it kicks back.

Traceback (most recent call last):

File "C:\Users\thiet01\Documents\Python Scripts\new 1.py", line 1, in

import pandas

ImportError: No module named 'pandas'

If you need any more information, please let me know and I can provide it.

Thanks in advance for any help.

like image 906
Tthieme Avatar asked Jun 27 '16 19:06

Tthieme


People also ask

Why it is showing no module named pandas?

The Python "ModuleNotFoundError: No module named 'pandas'" occurs when we forget to install the pandas module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install pandas command.

Why import pandas as PD is not working?

In most cases this error in Python generally raised: You haven't installed Pandas explicitly with pip install pandas. You may have different Python versions on your computer and Pandas is not installed for the particular version you're using.


1 Answers

I had the same problem for a long time. Today I tried a whole day and it finally worked. Below is the steps how I did it. I don't have theory for why the problem exist and how it is solved. I just know the following steps helped me get pandas going.

A. download first and install miniconda using the following code:

bash Miniconda2-latest-MacOSX-x86_64.sh

B. create an env for your project using following code:

conda create --name trypandas numpy pandas jupyter

C. going to your env and try jupyter notebook with pandas using:

source activate trypandas
jupyter notebook

Note: my own experience indicates:

  1. when I missed conda install jupyter, pandas only work in pure python environment, not in ipython nor in jupyter notebook;

  2. after conda install jupyter, pandas works in jupyter notebook now.

  3. the step B above installing jupyter together with numpy and pandas, there should not be a problem.

like image 190
Daniel Avatar answered Nov 15 '22 21:11

Daniel