【问题标题】:How to load large xml dataset file in python?如何在 python 中加载大型 xml 数据集文件?
【发布时间】:2020-07-25 20:27:31
【问题描述】:

您好,我正在使用 python 进行数据分析项目,我有一个大约 2.8GB 的​​ XML 文件,该文件太大而无法打开。我下载了帮助我打开文件的 EmEditor。问题是当我尝试像这样在 python google colaboratory 中加载文件时:

import xml.etree.ElementTree as ET
tree = ET.parse('dataset.xml')  //dataset.xml is the name of my file 
root = tree.getroot()

我得到的结果是 No such file or directory: 'dataset.xml' exists 。我的桌面上有我的 dataset.xml 文件,它可以使用 EmEditor 打开,这让我认为它可以通过 EmEditor 进行编辑和加载,但我不知道。感谢您帮助我在 python 中加载数据 谷歌实验室。

【问题讨论】:

标签: python xml directory load


【解决方案1】:

Google Colab 在来自 Google 的计算机上远程运行,无法访问您桌面上的文件。

要在 Python 中打开文件,您首先需要将文件传输到您的 colab 实例。有多种方法可以做到这一点,您可以在这里找到它们:https://colab.research.google.com/notebooks/io.ipynb

最简单的可能是这样的:

from google.colab import files

uploaded = files.upload()

for fn in uploaded.keys():
  print('User uploaded file "{name}" with length {length} bytes'.format(
      name=fn, length=len(uploaded[fn])))

尽管请记住,每次启动新的 colab 会话时,您都需要重新上传文件。这是因为 Google 想在您不使用的时候为他人使用该计算机,从而擦除计算机上的所有数据。

【讨论】:

  • 谢谢。我现在就试试
  • 仍然 0% 加载。
  • 当你在一个单元格中按下执行!ls时,它是否显示你的文件(可能在其他文件之间)?
  • 最后我用Visual Studio代码打开了文件。我将文件复制到我的项目路径中
猜你喜欢
  • 2012-12-31
  • 2021-03-29
  • 1970-01-01
  • 1970-01-01
  • 2017-11-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-12
相关资源
最近更新 更多