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.
Related
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')
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".
I always could run this code:
import pandas as pd
But I can't now, for some reason it raises:
>>> import pandas as pd
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pandas as pd
File "C:\Users\rep\Anaconda3\lib\site-packages\pandas\__init__.py", line 43, in <module>
from pandas.io.api import *
File "C:\Users\rep\Anaconda3\lib\site-packages\pandas\io\api.py", line 17, in <module>
from pandas.io.packers import read_msgpack, to_msgpack
File "C:\Users\rep\Anaconda3\lib\site-packages\pandas\io\packers.py", line 67, in <module>
from pandas.msgpack import Unpacker as _Unpacker, Packer as _Packer, ExtType
ModuleNotFoundError: No module named 'pandas.msgpack'
>>>
I was thinking it must be something I did when looking at pandas source code, since I was trying to find code from there.
It still works when I write in the command line activate updated, but I am just wondering what happened to the pandas without activated updated, what did I change and how can I fix it, I looked in my folder and don't see any files named pandas that interrupts this process.
Just for future readers, I solved it long ago by copying pandas from the environment to outside the environment, surely I accidentally modified pandas outside the environment.
Everything works as fine now. I am pretty sure I accidentally moved msgpack under io.
I am having an issue when trying to import:
from pandas.io.json import json_normalize
when running a python program I have made. The same import works when running the code manually from the command line.
I am using Windows 10, with Python 3.6.5 installed.
Example - working from command line:
>>> import pandas
>>> from pandas.io.json import json_normalize
>>> json_normalize
<function json_normalize at 0x08319C90>
Example - same code in test.py:
Traceback (most recent call last):
File "pandas.py", line 3, in <module>
import pandas as pd
File "C:\Users\Test\test.py", line 4, in <module>
from pandas.io.json import json_normalize
ModuleNotFoundError: No module named 'pandas.io'; 'pandas' is not a package
Any idea what I could check to see if I can resolve this?
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!