I am using Pandas for the first time and trying to import Pandas, DataFrame and pandas.io.data as such
import pandas as pd
from pandas import DataFrame
import pandas.io.data
I get the error
"ImportError: cannot import name DataFrame"
and
"ImportError: No module named io.data"
I have tried the following to find the source of error on Ubuntu 14.04:
$pip show pandas
-> Version: 0.14.0
Location: /home/new-pc/anaconda/lib/python2.7/site-packages
$$PATH
-> bash: /home/new-pc/anaconda/bin
Not sure where else to look for errors. Thanks for all the inputs.
You must be mixing Python installations, with several python programs/distributions (Anaconda), and maybe python version (2 and 3)
The following commands should not produce any error:
sudo apt-get install python
sudo pip install pandas
python -c'import pandas as pd; from pandas import DataFrame; import pandas.io.data'
It will happen if you call your file pandas.py and try to run it. You should rename the file then.
It will also occur if you save a pandas.py file in the Python directory. Check if you have any files called pandas.py there and rename/move those files to another location.
Try:
from pandas_datareader import data
as shown in the example here
Check if you have saved any file with same names as in pandas libraries, such as saving file name as DataFrame.py. Always avoid naming the program as same as library name check all the location.Once you remove/rename your python script will run without any issue.
Related
I am currently working with netCDF data in the Spyder IDE, however when I try to import 'Dataset' from the module
from netCDF4 import Dataset
it is giving me the following error: "No module named 'netCDF4'". I already installed the module but I guess it is not in the same environment where I installed spyder. How can I fix this? If it helps solving my question. When I try to install netCDF4 in the spyder console using 'pip install netCDF4' it gives the following error:
"/Applications/Spyder.app/Contents/MacOS/python: No module named pip
Note: you may need to restart the kernel to use updated packages."
I looked up the path of the module: '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/netCDF4'
and I guess the path for spyder is:
'/Applications/Spyder.app/Contents/MacOS/python'
How can I make sure that they are both located in the same environment?
I tried to look up the issue, however nothing really solved my problem.
Would be glad if anyone could help me out.
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from netCDF4 import Dataset
from cftime import numb2date
import tifffile as tifffile
# define arrays
XNR=[] # number
Xdt=[] # time
YGP=[] # GPP
YPP=[] # PPFD
# read csv file and extract column 0 (timestemp), PPFD (column 54) and GPP (column 312)
# take a file from FLUXNET for validation of the GPP model
with open(r'/Users/janoschbeer/Documents/Studium/ESS/ES_Observ/Assignments/Lab6/FLX_SJ-Adv_FLUXNET2015_SUBSET_2011-2014_1-4/FLX_SJ-Adv_FLUXNET2015_SUBSET_DD_2011-2014_1-4.csv') as csv:
lines = csv.readlines()
for i in range(2, len(lines)):
tmp=lines[i].split(",")
XNR.append(float(i))
Xdt.append(float(tmp[0]))
YGP.append(float(tmp[312]))
YPP.append(float(tmp[54]))
Lately I've been learning a bit about Python. Jupyter notebooks seem like a good idea in theory, in practice I'm having some difficulty setting up the python modules within a Jupyter environment.
For example, I found this neat geographical data article and I want to follow along. There is a very nice github project that I downloaded to follow along.
Start up Jupyter and everything looks in order until I run the first code block:
import pandas as pd
import re
from datetime import datetime
from dateutil.parser import parse
import missingno as msno
import numpy as np
import seaborn as sb
import matplotlib.pyplot as plt
import json
This immediately generates an error:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-422e89229f53> in <module>
----> 1 import pandas as pd
2 import re
3 from datetime import datetime
4 from dateutil.parser import parse
5 import missingno as msno
ModuleNotFoundError: No module named 'pandas'
There are quite a few modules and I guess I can go into the command line to add them each individually. That doesn't seem efficient. Is there some other 'Jupyter' or 'Conda' way to do this?
Within Jupyter notebooks you can execute command line methods using ! at the start of the line e.g.
! conda install pandas --yes
More detail on the inner working is discussed in this question:
Running interactive command line code from Jupyter notebook
Thanks to #PaulH for pointing out the need to add the --yes flag.
just run this in Jupyter:
!pip install <the name of the module>, <the name of the module>, <the name of the module>...
this will install the module you choose.
For example :
!pip install pandas, re, ...
I've installed pandas using pip3. I'm able to import pandas in the MacOS terminal without issue, but whenever I try to import it in Atom, using the script package, I get an error.
This error is:
ImportError: No module named pandas
I don't get this error when trying to import numpy in Atom.
I assume you are using Script package to run python scripts in Atom.
Following approach worked for me.
Lets first check which python version Atom is using. Try this in Atom.
import sys
print('Python: {}'.format(sys.version))
If you see output as python version 2.x then
Point Atom to use python 3 by updating Atom ->Preferences -> Open Config Folder ->Packages -> Script->lib->grammars->python.coffee. Change
command: 'python' to command: 'python3' .
Save and Close Atom.
Run your code again to check python version. Now it should say 3.x
pip install pandas
You can run following python code in atom to check versions of commonly used python libraries for ML.
# Check the versions of libraries
# Python version
import sys
print('Python: {}'.format(sys.version))
# scipy
import scipy
print('scipy: {}'.format(scipy.__version__))
# numpy
import numpy
print('numpy: {}'.format(numpy.__version__))
# matplotlib
import matplotlib
print('matplotlib: {}'.format(matplotlib.__version__))
# pandas
import pandas
print('pandas: {}'.format(pandas.__version__))
# scikit-learn
import sklearn
print('sklearn: {}'.format(sklearn.__version__))
i had this in some new files I created to test Pandas, but on closer inspection I found I was missing this line in my new files, as I was adding the library:
#!/usr/local/bin/python3
On adding this definition it worked perfectly via Python3.
I am running Python 2.7.10 on a Macbook.
I have installed:
Homebrew
Python 2.x, 3.x
NI-VISA
pip
pyvisa, pyserial, numpy
PyVISA
Anaconda
Pandas
I am attempting to run this script. A portion of it can be read here:
import visa
import time
import panda
import sys
import os
import numpy
os.system('cls' if os.name == 'nt' else 'clear') #clear screen
rm = visa.ResourceManager()
rm.list_resources()
print(rm.list_resources())
results = panda.DataFrame(columns=['CURR', 'VOLT', 'TIME'])
This is what is returned on the command line, below.
Note the line that says
AttributeError: 'module' object has no attribute 'DataFrame'
(u'USB0::0x05E6::0x2280::4068201::INSTR', u'ASRL1::INSTR', u'ASRL2::INSTR', u'ASRL4::INSTR')
Traceback (most recent call last):
File "k2280.py", line 14, in <module>
results = panda.DataFrame(columns=['CURR', 'VOLT', 'TIME'])
AttributeError: 'module' object has no attribute 'DataFrame'
Any help or insight on this issue would be appreciated.
It's pandas, not panda, so use import pandas instead. It's also common practice to import pandas as pd for convenience:
import pandas as pd
df = pd.DataFrame()
The module is called pandas not panda
python3 -m pip install pandas
import pandas as pd
pd.DataFrame()
Please read if you're new to python.
As I am also new to python since 2 days and going through the tutorial.
What I know is pandas are the packages we install in the python library to the machine we are using.
As I am new and I was practicing to import and use pandas.DataFrame I kept my filename as pandas.py
And here is the error I was doing. I can't use pandas.py because the machine is assuming its module inside this pandas.py
I changed the filename and it start working fine.
Few things to know if you're getting errors.
You are using pandas.py as filename, you need to change the file name
You are not importing pandas in the file and started working on its module
You are not using DataFrame in camel case
I think these 3 things should be kept in mind to use DataFrame to avoid this error.
This is my first time using a jupyter notebook.
I was trying to import the panda module:
import panda as pd
but I get the following error:
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/panda/__init__.py in <module>()
----> 1 from request import PandaRequest
ImportError: cannot import name 'PandaRequest'
How to fix this?
Edit: I wanted to use pandas but typed panda instead. :'D
You have installed and imported the panda module, which is the a Python implementation of the Panda REST interface and which has incomplete dependencies.
What you probably want to do is install pandas (with the final s) and import that.
I got the same problem and come up with the following solutions:
import pandas as pd
instead of
import panda as pd
It is called pandas.
Execute pip install panda. You don't have the Panda module.
Edit: My mistake, it looks like there's an error within the Panda module itself. Does it rely on PandaRequest?