首页 > 解决方案 > AttributeError:模块 'pandas' 没有带有 rapsberry Pi 的属性 'Dataframe'

问题描述

我知道有类似的问题,但没有人能够为我提供答案。我在树莓派(模型 3)上运行 python 脚本。我正在使用 python 3,并且通过 pip install pandas 安装了 pandas。我的代码能够运行该行import pandas as pd,但test = pd.Dataframe给了我一个错误:AttributeError: module 'pandas' has no attribute 'Dataframe'

如下面的代码所示,我检查了我的代码是否有正确的 pandas 模块。

我还直接在python中检查:

`Python 3.7.3 (default, Apr  3 2019, 05:39:12)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd

这工作正常:

>>> test = pd.Dataframe()

但这给了我以下错误消息:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/pi/.local/lib/python3.7/site-packages/pandas/__init__.py", line 214, in __getattr__
raise AttributeError("module 'pandas' has no attribute'{}'".format(name))
AttributeError: module 'pandas' has no attribute 'Dataframe'`

我检查了我的文件夹的名称。我没有名为 pandas 或 pd 的文件。我的树莓派是全新的。该脚本是文件夹中的唯一文件。

密码给了我:/home/pi/sensehat_projects/Raspb_fitbit/rasp_code

和 ls -a: . .. .DS_Store weather_script.py

try:
from pip._internal.operations import freeze
except ImportError:  # pip < 10.0
    from pip.operations import freeze

x = freeze.freeze()
for p in x:
    print(p) 

# prints a list of modules (pandas==0.25.0)
from sense_hat import SenseHat
import time
import sys
import os
import pandas as pd

data = pd.Dataframe()


Traceback (most recent call last):
  File "weather_script.py", line 18, in <module>
    data = pd.Dataframe()
  File "/home/pi/.local/lib/python3.7/site-packages/pandas/__init__.py", line 214, in __getattr__
    raise AttributeError("module 'pandas' has no attribute '{}'".format(name))
AttributeError: module 'pandas' has no attribute 'Dataframe'

我相信这段代码应该正确地构建一个空的熊猫数据框。

标签: pythonpandasraspberry-pi3

解决方案


利用

data = pd.DataFrame()

带有大写字母“F”。pd.Dataframe() (没有大写的'F')不存在,所以它会抛出显示的错误。


推荐阅读