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

4.3k Views Asked by At

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.

3

There are 3 best solutions below

0
On

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()
3
On

The module is called pandas not panda

python3 -m pip install pandas

import pandas as pd

pd.DataFrame()

0
On

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.

  1. You are using pandas.py as filename, you need to change the file name
  2. You are not importing pandas in the file and started working on its module
  3. 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.