I am trying to import panda in python script .
import pandas as pd
import numpy as np
But I am getting below error :
Error from Scripts is : Script failed to run:
Error: [Traceback (most recent call last):
File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'pandas'
] (2604) (2603)
This python script I am using in Cortex XSOAR (demisto).
I have to sort values in columns in one table. Google results shows that have to use pandas.DataFrame.sort_values. Hence, using this.
Please help me on fixing error with pandas module import or suggest me if there is any other way I can sort table values based on 1 column i.e integer values
Thanks in advance ,
NVP
Did you install pandas ?
py -m pip install pandas
I would suggest you to check where you installed pandas and use sys to append that path to your code.
For example:
import sys
sys.path.append(r'c:\users\NVP\appdata\local\programs\python\python39\lib\site-packages')
Related
I'm trying to import autograd with the following line of code:
import autograd.numpy as np
However, I'm getting the following error when trying to run the script:
Traceback (most recent call last):
File "autograd.py", line 1, in <module>
import autograd.numpy as np
File "/home/hakon/Documents/FYS_STK4155/project2/code and plots/test/autograd.py", line 1, in <module>
import autograd.numpy as np
ModuleNotFoundError: No module named 'autograd.numpy'; 'autograd' is not a package
I've tried installing autograd through pip, pip3 and conda, but the error remains the same.
The problem is that your module (the one that you're running) has the same name that you're trying to import: autograd (.py). Try renaming your file and running it again.
aaossa's answer worked for me. If changing the module name that you are running doesn't work, please check if there is any other autograd(.py) that you created existing in your current directory. If so, you also need to change that file's name or delete it so that you can import "autograd".
So far I have done following:
import os
os.environ["SPARK_HOME"] = '/usr/local/spark/'
os.environ["PYSPARK_PYTHON"] = '/opt/conda/bin/python'
from pyspark import SparkContext
But when I run I get the error:
ssh://vagrant#127.0.0.1:2222/opt/conda/bin/python -u /home/vagrant/src/spark.py
Traceback (most recent call last):
File "/home/vagrant/src/spark.py", line 6, in <module>
from pyspark import SparkContext
ModuleNotFoundError: No module named 'pyspark'
Even If I try to run it without using Python3 path I get the same error.
The SPARK version of Python is given here:
/usr/local/spark/python
What wrong am I doing?
Ideally I want to use Python3 for my scripts.
try to:
import sys
sys.path.append('/usr/local/spark/python/pyspark')
or a direct way:
sudo ln -s /usr/local/spark/python/pyspark /usr/local/lib/python2.7/site-packages
I am using Apache-Spark (pyspark) and everything works fine. Now, I am trying to load a data that may or may not exist. So, I am trying to catch the Py4JJavaError and am trying to import it as follows:
from py4j.java_gateway import Py4JJavaError
ImportError: cannot import name Py4JJavaError
When I unzip this file:
/usr/local/Cellar/apache-spark/1.6.2/python/lib/py4j-0.9-src.zip
And inspect this file:
java_gateway.py
I find no Py4JJavaError.
What am I doing wrong? Any other place / path I should be using instead?
Try from py4j.protocol import Py4JJavaError.
I'm using Python, and just start importing pandas, then the terminal reports failure like this:
Traceback (most recent call last):
File "C:/Users/L30607/PycharmProjects/untitled1/pandas.py", line 1, in <module>
import pandas as pd
Any idea whats wrong?
If you have installed pandas, then your local pandas.py is shadowing the pandas library. To get the original pandas, do:
from __future__ import absolute_import
import pandas as pd
Or save the trouble and just rename your own script to something else: my_pandas.py.
I wrote a python script over the summer that uses NumPy and Pandas to help me code some corpus data for the linguistics/psych lab I work in. All was fine until I upgraded to OSX Mavericks -- since then the script throws the following ImportError:
No module named dateutil.parser
Traceback (most recent call last):
File "/Users/nicholasmoores/Documents/Research/DataFrame_by_child1.9.2.py", line 30, in <module>
import pandas as pd #you will have to go through the potentially arduous process
File "/Library/Python/2.7/site-packages/pandas-0.11.0-py2.7-macosx-10.8-intel.egg/pandas/__init__.py", line 6, in <module>
from . import hashtable, tslib, lib
File "tslib.pyx", line 31, in init pandas.tslib (pandas/tslib.c:48027)
ImportError: No module named dateutil.parser
logout
which is quite frustrating! I don't know why anything else on the script would fail to work after dealing with my imports, and numpy and pandas were the only ones I was expecting to have trouble with after upgrading... FYI I'm now running Python 2.7.6
import os.path
import re
import sys
import nltk
import pickle
import numpy as np
import pandas as pd
from nltk.corpus.reader import CHILDESCorpusReader
from nltk.probability import ConditionalFreqDist, FreqDist
fd = FreqDist()
cfd = ConditionalFreqDist()
I'm sure it has to do with OSX's inhouse python getting upgraded and I suppose Pandas is trying to look for python syntax in the dateutil module that has since changed or something like that. If anyone has any suggestions they would be much appreciated as I was hoping to get a lot of data coded over the holidays!
Dateutil is a dependency of pandas, it looks like somehow this module is no longer on your system.
You'll need to (re)install dateutil:
sudo pip install dateutil
What ended up fixing the problem was redownloading and reinstalling dateutil. I'm still not completely sure where the fault was that caused Pandas to not be able to access it anymore, but I'm glad I got it all working again!