【问题标题】:Cannot read ".parquet" files in Azure Jupyter Notebook (Python 2 and 3)无法在 Azure Jupyter Notebook(Python 2 和 3)中读取“.parquet”文件
【发布时间】:2018-12-20 16:22:24
【问题描述】:

我目前正在尝试使用 Azure Jupyter Notebooks 打开 parquet 文件。我已经尝试了两个 Python 内核(2 和 3)。 pyarrow 安装后,我只能在 Python 内核为 2(不适用于 Python 3)时导入模块

这是我到目前为止所做的(为了清楚起见,我没有提及我所有的各种尝试,例如使用 conda 而不是 pip,因为它也失败):

!pip install --upgrade pip
!pip install -I Cython==0.28.5
!pip install pyarrow

import pandas  
import pyarrow
import pyarrow.parquet

#so far, so good

filePath_parquet = "foo.parquet"
table_parquet_raw = pandas.read_parquet(filePath_parquet, engine='pyarrow')

如果我离线执行此操作(使用 Spyder,Python v.3.7.0),这会很好。但使用 Azure Notebook 失败。

 AttributeErrorTraceback (most recent call last)
<ipython-input-54-2739da3f2d20> in <module>()
      6 
      7 #table_parquet_raw = pd.read_parquet(filePath_parquet, engine='pyarrow')
----> 8 table_parquet_raw = pandas.read_parquet(filePath_parquet, engine='pyarrow')

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

有什么想法吗?

提前谢谢你!

编辑:

非常感谢您的回复彼得潘! 我已经输入了这些语句,这是我得到的:

1.

    print(pandas.__dict__)

=> read_parquet 没有出现

2.

    print(pandas.__file__)

=> 我明白了:

    /home/nbuser/anaconda3_23/lib/python3.4/site-packages/pandas/__init__.py
  1. 导入系统; print(sys.path) => 我明白了:

    ['', '/home/nbuser/anaconda3_23/lib/python34.zip',
    '/home/nbuser/anaconda3_23/lib/python3.4',
    '/home/nbuser/anaconda3_23/lib/python3.4/plat-linux',
    '/home/nbuser/anaconda3_23/lib/python3.4/lib-dynload',
    '/home/nbuser/.local/lib/python3.4/site-packages',
    '/home/nbuser/anaconda3_23/lib/python3.4/site-packages',
    '/home/nbuser/anaconda3_23/lib/python3.4/site-packages/Sphinx-1.3.1-py3.4.egg',
    '/home/nbuser/anaconda3_23/lib/python3.4/site-packages/setuptools-27.2.0-py3.4.egg',
    '/home/nbuser/anaconda3_23/lib/python3.4/site-packages/IPython/extensions',
    '/home/nbuser/.ipython']
    

请问你有什么想法吗?

编辑 2:

亲爱的@PeterPan,我已经输入了!conda update conda!conda update pandas:当检查Pandas 版本时(pandas.__version__),它仍然是0.19.2

我也试过!conda update pandas -y -f,它返回: `获取包元数据............ 解决包装规格:.

环境/home/nbuser/anaconda3_23安装包方案:

将安装以下新包:

pandas: 0.19.2-np111py34_1`

输入时: !pip install --upgrade pandas

我明白了:

Requirement already up-to-date: pandas in /home/nbuser/anaconda3_23/lib/python3.4/site-packages Requirement already up-to-date: pytz>=2011k in /home/nbuser/anaconda3_23/lib/python3.4/site-packages (from pandas) Requirement already up-to-date: numpy>=1.9.0 in /home/nbuser/anaconda3_23/lib/python3.4/site-packages (from pandas) Requirement already up-to-date: python-dateutil>=2 in /home/nbuser/anaconda3_23/lib/python3.4/site-packages (from pandas) Requirement already up-to-date: six>=1.5 in /home/nbuser/anaconda3_23/lib/python3.4/site-packages (from python-dateutil>=2->pandas)

最后,打字时:

!pip install --upgrade pandas==0.24.0

我明白了:

Collecting pandas==0.24.0 Could not find a version that satisfies the requirement pandas==0.24.0 (from versions: 0.1, 0.2b0, 0.2b1, 0.2, 0.3.0b0, 0.3.0b2, 0.3.0, 0.4.0, 0.4.1, 0.4.2, 0.4.3, 0.5.0, 0.6.0, 0.6.1, 0.7.0rc1, 0.7.0, 0.7.1, 0.7.2, 0.7.3, 0.8.0rc1, 0.8.0rc2, 0.8.0, 0.8.1, 0.9.0, 0.9.1, 0.10.0, 0.10.1, 0.11.0, 0.12.0, 0.13.0, 0.13.1, 0.14.0, 0.14.1, 0.15.0, 0.15.1, 0.15.2, 0.16.0, 0.16.1, 0.16.2, 0.17.0, 0.17.1, 0.18.0, 0.18.1, 0.19.0rc1, 0.19.0, 0.19.1, 0.19.2, 0.20.0rc1, 0.20.0, 0.20.1, 0.20.2, 0.20.3, 0.21.0rc1, 0.21.0, 0.21.1, 0.22.0) No matching distribution found for pandas==0.24.0

因此,我的猜测是问题出在 Azure 中管理包的方式上。更新一个包(这里是 Pandas),应该会导致更新到可用的最新版本,不是吗?

【问题讨论】:

    标签: python azure jupyter-notebook azure-machine-learning-studio azure-machine-learning-workbench


    【解决方案1】:

    我尝试在我的 Azure Jupyter Notebook 上重现您的问题,但失败了。如果不执行!pip install --upgrade pip!pip install -I Cython==0.28.5 这两个步骤,对我来说没有任何问题,我认为这并不重要。

    请运行下面的代码来检查你的导入包pandas是否正确。

    1. 运行print(pandas.__dict__)检查输出中是否有read_parquet函数的描述。
    2. 运行print(pandas.__file__) 以检查您是否导入了不同的pandas 包。
    3. 运行import sys; print(sys.path)检查路径的顺序,这些路径下是否有相同的命名文件或目录。

    如果有相同的文件或目录名为pandas,您只需将其重命名并重新启动您的ipynb 即可重新运行。这是一个常见问题,您可以参考这些 SO 线程 AttributeError: 'module' object has no attribute 'reader'Importing installed package from script raises "AttributeError: module has no attribute" or "ImportError: cannot import name"

    在其他情况下,请更新您的帖子以获取更多详细信息让我知道。


    最新的pandas 版本应该是0.23.4,而不是0.24.0

    我试图通过在0.19.20.23.3不同版本的文档中搜索函数名称read_parquet来找出支持read_parquet功能的最早版本的pandas。然后,我发现pandas0.21.1版本之后支持read_parquet功能,如下。

    What's New 版本0.21.1 中显示的新功能

    根据您的EDIT 2 描述,您似乎在 Azure Jupyter Notebook 中使用 Python 3.4。并非所有 pandas 版本都支持 Python 3.4 版本。

    0.21.10.22.0 版本正式支持 Python 2.7、3.5 和 3.6,如下所示。

    PyPI page for pandas也需要Python版本如下。

    所以你可以尝试在Python 3.4的当前笔记本中安装pandas版本0.21.10.22.0。如果失败,请在Python中创建一个新的笔记本2.7&gt;=3.5安装pandas版本&gt;= 0.21.1使用函数read_parquet

    【讨论】:

    • 非常感谢@PeterPan 的回答!我已经编辑了我的问题。你能看看吗? -最好的问候
    • @Menas 尝试通过pandas.__version__ 打印您的熊猫版本。在我的本地机器上,我在我的 miniconda 环境中通过conda install pandas 安装了pandas,版本是0.23.4,它具有read_parquet 的功能。您可以尝试在 iPython 中通过!conda update &lt;conda or pandas&gt; 更新您的 conda 或 pandas。
    • 亲爱的@PeterPan,您有时间可以看看我的最新更新吗? (或其他任何知道如何解决此问题的人:-)
    • @Menas 请查看我的更新答案。在我为您研究后,您可以尝试在 Python 3.4 的当前笔记本中安装 pandas 版本 0.21.10.22.0。如果失败,请在 Python 2.7&gt;=3.5 中创建一个新笔记本来安装 pandas 版本 &gt;= 0.21.1 以使用函数 read_parquet。
    • 亲爱的@PeterPan,非常感谢,问题已经解决了!我已将内核更新为 2(Python 2.7)并将 Pandas 更新为 0.22.0。安装 PyArrow 后,一切都像魅力一样!
    猜你喜欢
    • 2021-10-09
    • 2015-06-21
    • 1970-01-01
    • 1970-01-01
    • 2019-11-24
    • 2021-02-26
    • 1970-01-01
    • 2020-11-04
    • 2017-03-14
    相关资源
    最近更新 更多