【发布时间】:2023-03-03 13:05:02
【问题描述】:
df01 = pd.read_json('/content/drive/MyDrive/project/rio_bq_2019000000000000',lines=True)
此行没有错误。但它在下一行有错误,我不明白这里发生了什么。我在 google colab 上读到的
df01
我收到如下错误:
AttributeError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/IPython/core/formatters.py in __call__(self, obj)
336 method = get_real_method(obj, self.print_method)
337 if method is not None:
--> 338 return method()
339 return None
340 else:
1 frames
/usr/local/lib/python3.7/dist-packages/pandas/io/formats/format.py in to_html(self, buf, encoding, classes, notebook, border)
986 notebook : {True, False}, optional, default False
987 Whether the generated HTML is for IPython Notebook.
--> 988 border : int
989 A ``border=border`` attribute is included in the opening
990 ``<table>`` tag. Default ``pd.options.display.html.border``.
AttributeError: 'NotebookFormatter' object has no attribute 'get_result'
Building Level ... lng localtime
0 TPS1 Level 2 ... -43.249902 2019-08-01 02:52:33.289 UTC
1 TPS1 Level 2 ... -43.250474 2019-08-01 02:52:35.488 UTC
2 TPS1 Level 2 ... -43.251573 2019-08-01 02:52:36.268 UTC
3 TPS1 Level 2 ... -43.249719 2019-08-01 02:52:41.537 UTC
4 TPS1 Level 2 ... -43.249737 2019-08-01 02:52:41.538 UTC
... ... ... ... ... ...
3372900 TPS1 Level 2 ... -43.250513 2019-08-25 10:21:01.483 UTC
3372901 TPS1 Level 2 ... -43.250169 2019-08-25 10:21:02.024 UTC
3372902 TPS1 Level 2 ... -43.250169 2019-08-25 10:21:02.026 UTC
3372903 TPS1 Level 2 ... -43.249944 2019-08-25 10:21:02.536 UTC
3372904 TPS1 Level 2 ... -43.249944 2019-08-25 10:21:02.536 UTC
我可以看到数据已导入 df01,如错误输出底部所示。但我不能使用它。为什么?我该如何解决这个问题?
如果您需要,这是我的示例数据文件
{"Building":"TPS2","Level":"Level 3","ClientMacAddr":"8c:8e:f2:7d:2f:de","lat":-22.813377029213196,"lng":-43.247283256092494,"localtime":"2019-11-28 17:49:00.753 UTC"}
{"Building":"TPS2","Level":"Level 3","ClientMacAddr":"8c:8e:f2:7d:2f:de","lat":-22.813377029213196,"lng":-43.247283256092494,"localtime":"2019-11-28 17:49:00.753 UTC"}
{"Building":"TPS2","Level":"Level 3","ClientMacAddr":"00:27:15:00:10:1f","lat":-22.814628521677054,"lng":-43.24741506118599,"localtime":"2019-11-28 17:49:01.58 UTC"}
{"Building":"TPS2","Level":"Level 3","ClientMacAddr":"00:27:15:00:10:1f","lat":-22.814628521677054,"lng":-43.24741506118599,"localtime":"2019-11-28 17:49:01.58 UTC"}
在这之前我只有两行
import pandas as pd
drive.mount("/content/drive")
【问题讨论】:
-
我认为这里没有足够的信息来帮助您。如果输入文件的读取和反 JSON 没有失败,则
df01必须仅包含列表、映射和原子数据类型。使用该值做任何事情本身不可能导致执行您向我们展示的代码。那么你在用df01做什么呢?是什么导致您向我们展示的代码被执行?还有一个问题是,所引用的属性get_result在您向我们展示的代码中的任何地方都找不到,因此很难知道为什么会发生这种情况。 -
@CryptoFool 从0-3372904行属性错误后的结果可以看出。所以我猜笔记本已经读过了,但输出是错误的。我只在此行之前使用 drive.mount 并将 pandas 作为 pd 导入。我可以阅读我的 txt 文件,向您展示我的文件中包含的内容
-
你不能单独执行
df01这不是我担心的事情。它不是有效的 Python,因此它也是语言或环境的某种扩展。如果您认为它可以在 REPL 中工作,那是对的,但这是 REPL 的扩展,而不是 Python 语言本身的一部分。 - 话虽如此,如果它适用于某些变量但不适用于其他变量,那么我将其称为错误,如果它导致像您看到的错误一样,无论如何它都是错误。
标签: python jupyter-notebook google-colaboratory