【问题标题】:dask - read_json into dataframe ValueErrordask - 将_json读入数据框ValueError
【发布时间】:2019-11-09 06:53:42
【问题描述】:

这里的一个最小示例:我有一个 json 文件 xaa.json,其内容如下所示(来自 stackoverflow 存档的两行):

[
  {"Id": 11, "Body": "<p>Given a specific <code>DateTime</code> value", "Title": "Calculate relative time in C#", "Comments": "There is the .net package https://github.com/NickStrupat/TimeAgo which pretty much does what is being asked."},
  {"Id": 7888, "Body": "<p>You need to use an <a href=\\"http://en.cppreference.com/w/cpp/io/basic_ifstream\\" rel=\\"noreferrer\\"><code>ifstream</code></a> if you just want to read (use an <code>ofstream</code> to write, or an <code>fstream</code> for both).</p>&#xA;&#xA;<p>To open a file in text mode, do the following:</p>&#xA;&#xA;<pre><code>ifstream in(\\"filename.ext\\", ios_base::in); // the in flag is optional&#xA;</code></pre>&#xA;&#xA;<p>To open a file in binary mode, you just need to add the \\"binary\\" flag.</p>&#xA;&#xA;<pre><code>ifstream in2(\\"filename2.ext\\", ios_base::in | ios_base::binary ); &#xA;</code></pre>&#xA;&#xA;<p>Use the <a href=\\"http://en.cppreference.com/w/cpp/io/basic_istream/read\\" rel=\\"noreferrer\\"><code>ifstream.read()</code></a> function to read a block of characters (in binary or text mode).  Use the <a href=\\"http://en.cppreference.com/w/cpp/string/basic_string/getline\\" rel=\\"noreferrer\\"><code>getline()</code></a> function (it's global) to read an entire line.</p>&#xA;", "Title": null, "Comments": "+1 for noting that the global getline() function is to be used instead of the member function."}
]

我想将这样的 json 文件加载到 dask 数据框中。我用:

so_posts_df = dd.read_json('./xaa.json', orient='columns').compute()

我收到此错误:

ValueError: Unexpected character found when decoding object value

查看内容后,我认为是“\\”的东西导致了它。所以,当我删除它们时,(编辑器 - IntelliJ 说它是干净漂亮的 JSON),当我运行相同的 read_json 时,它能够读入 df 并很好地显示它们。

所以,我有 2 个问题:(a) read_json 参数 "errors" 的值是什么? (b) 在读入 dask 数据帧之前,如何正确预处理 json 文件?双引号和双转义的存在似乎导致了问题。

[这可能根本不是一个大问题...]...

【问题讨论】:

    标签: dask


    【解决方案1】:

    pandas.read_json 也会失败。我建议首先尝试让 Pandas 正常工作,然后尝试使用 dask 数据框进行相同的工作负载。在向 Pandas 提问时,您可能会得到更好的支持。

    【讨论】:

      猜你喜欢
      • 2023-03-29
      • 2019-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-08
      • 2020-07-28
      • 2023-03-24
      • 1970-01-01
      相关资源
      最近更新 更多