AttributeError: 'module' object has no attribute 'DataFrame' - python

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.

Related

Hi I am gettin AttributeError: 'list' object has no attribute 'get'

data = data.get('aggs')[0].get('subreddit')
df = pandas.DataFrame.from_records(data)[0:10]
You'll need to import the packages (or modules) used in your code:
import requests
import pandas # this is missing from the article you referred to
Also, if you haven't installed Plotly, you'll want to do that with either
pip install plotly or conda install plotly.
There are several good articles about import and Python modules/packages, such as https://www.devdungeon.com/content/python-import-syspath-and-pythonpath-tutorial or How to import other Python files?

ModuleNotFoundError: No module named 'pandas.rpy'

I'm trying to import pandas as pd. I get ModuleNotFoundError: No module named 'pandas.rpy'. Why? I use pandas 0.20.1 + python 3.6 x64 + Windows 7 .
Example:
import os
os.environ['R_HOME'] = 'C:\Program Files\R\R-3.4.0'
os.environ['R_USER'] = 'bob'
import rpy2.robjects as robjects
import pandas.rpy.common as com
import pandas as pd
Returns:
Traceback (most recent call last):
File "C:\doc\GitHub\proj\src\open_rdata.py", line 19, in <module>
import pandas.rpy.common as com
ModuleNotFoundError: No module named 'pandas.rpy'
pandas.rpy module was deprecated and later removed. It does not exist in the version you are currently using.
You can either downgrade your pandas version, or better yet, have a look at the new rpy2 project.
From pandas documentation:
Up to pandas 0.19, a pandas.rpy module existed with functionality to
convert between pandas and rpy2 objects. This functionality now lives
in the rpy2 project itself. See the updating section of the previous
documentation for a guide to port your code from the removed
pandas.rpy to rpy2 functions.
You can see the rpy2 documentation here, and panda's reference for it here.
edit: per Analytical Monk's comment, corrected the phrasing to refer rpy2 as a different library, and not a part of pandas

How do I fix: ImportError: cannot import name 'PandaRequest'?

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?

ImportError: cannot import name DataFrame

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.

Python does not recognize Pandas functions

So I installed pandas and I can run these first two lines no problem:
import pandas as pd
import numpy as np
But this line:
pd.read_csv('train.csv', header=0)
gives me the following error:
AttributeError: 'module' object has no attribute 'read_csv'
Is there something wrong with the module?
I am running Python 2.7.5 with Mac OS X 10.9.2
Your input is appreciated!
EDIT: I was running a file named pandas.py, which is the same name as the 'pandas' module, hence the error.

Categories

Resources