【发布时间】: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>

<p>To open a file in text mode, do the following:</p>

<pre><code>ifstream in(\\"filename.ext\\", ios_base::in); // the in flag is optional
</code></pre>

<p>To open a file in binary mode, you just need to add the \\"binary\\" flag.</p>

<pre><code>ifstream in2(\\"filename2.ext\\", ios_base::in | ios_base::binary ); 
</code></pre>

<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>
", "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