- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试生成一个 JSON blob,其中包含从我的数据框中的一系列数据生成的列表。当我运行 to_json(orient='values')
时,它适本地将系列转换为仅包含系列值的列表,但随后将列表用单引号引起来,如果有人处理,则很难解析此数据它。有没有一种好方法可以将系列转换为 JSON 对象,但不将列表用单引号引起来?
代码:
# Create empty JSON blob
output_json = {}
# Add to JSON output
output_json['count_time_fitness_timeseries'] = {
'x': df.fitness_date.to_json(orient='values'),
'y': df.minutes_fitness.to_json(orient='values'),
'labels': df.minutes_fitness_hhmm.to_json(orient='values')
}
print(output_json)
例子:
{
'count_time_fitness_timeseries': {
'x': '["2020-04-01","2020-04-02","2020-04-03","2020-04-04","2020-04-05","2020-04-06","2020-04-07","2020-04-08","2020-04-09","2020-04-10","2020-04-11","2020-04-12","2020-04-13","2020-04-14","2020-04-15","2020-04-16","2020-04-17","2020-04-18","2020-04-19","2020-04-20","2020-04-21","2020-04-22","2020-04-23","2020-04-24","2020-04-25","2020-04-26","2020-04-27","2020-04-28","2020-04-29","2020-04-30","2020-05-01","2020-05-02","2020-05-03","2020-05-04","2020-05-05","2020-05-06","2020-05-07","2020-05-08","2020-05-09","2020-05-10","2020-05-11","2020-05-12","2020-05-13","2020-05-14","2020-05-15","2020-05-16","2020-05-17","2020-05-18","2020-05-19","2020-05-20","2020-05-21","2020-05-22","2020-05-23","2020-05-24","2020-05-25","2020-05-26","2020-05-27","2020-05-28","2020-05-29","2020-05-30","2020-05-31","2020-06-01","2020-06-02","2020-06-03","2020-06-04","2020-06-05","2020-06-06","2020-06-07","2020-06-08","2020-06-09","2020-06-10","2020-06-11","2020-06-12","2020-06-13","2020-06-14","2020-06-15","2020-06-16","2020-06-17","2020-06-18","2020-06-19","2020-06-20","2020-06-21","2020-06-22","2020-06-23","2020-06-24","2020-06-25","2020-06-26","2020-06-27","2020-06-28","2020-06-29","2020-06-30","2020-07-01"]',
'y': '[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,461.0,421.0,519.0,502.0,511.0,513.0,496.0,480.0,364.0,498.0,467.0,477.0,431.0,419.0,471.0,391.0,481.0,494.0,506.0,464.0,474.0,383.0,385.0,470.0,465.0,574.0,473.0,431.0,497.0,null,482.0,492.0,494.0,469.0,395.0,427.0,346.0,416.0,461.0,486.0,451.0,533.0,null,462.0,461.0,477.0,458.0,484.0,389.0,null,472.0,462.0,486.0,489.0,483.0,426.0,453.0,489.0,467.0,474.0,451.0,450.0,470.0,null,247.0,502.0,464.0]',
'labels': '[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,"7:41","7:01","8:39","8:22","8:31","8:33","8:16","8:00","6:04","8:18","7:47","7:57","7:11","6:59","7:51","6:31","8:01","8:14","8:26","7:44","7:54","6:23","6:25","7:50","7:45","9:34","7:53","7:11","8:17",null,"8:02","8:12","8:14","7:49","6:35","7:07","5:46","6:56","7:41","8:06","7:31","8:53",null,"7:42","7:41","7:57","7:38","8:04","6:29",null,"7:52","7:42","8:06","8:09","8:03","7:06","7:33","8:09","7:47","7:54","7:31","7:30","7:50",null,"4:07","8:22","7:44"]'
}
最佳答案
试试这个:
import json
#.... your code
print(json.dumps(output_json))
关于python - 防止 Pandas to_json() 将列表用单引号引起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62980921/
在线编写 yacc 代码的教程使用单引号表示分号和其他字符: ';' '+' '-' (etc) 但是在使用时: '' 在我将其更改为双引号之前,我遇到了错误: "" 相似地, '>=' '==
MySQL documentation说它应该是\'。然而,scite 和 mysql 都显示 '' 有效。我看到了,它有效。我该怎么办? 最佳答案 您引用的 MySQL 文档实际上比您提到的要多一些
MySQL documentation说它应该是\'。然而,scite 和 mysql 都显示 '' 有效。我看到了,它有效。我该怎么办? 最佳答案 您引用的 MySQL 文档实际上比您提到的要多一些
MySQL documentation说它应该是\'。然而,scite 和 mysql 都显示 '' 有效。我看到了,它有效。我该怎么办? 最佳答案 您引用的 MySQL 文档实际上比您提到的要多一些
MySQL documentation说它应该是\'。然而,scite 和 mysql 都显示 '' 有效。我看到了,它有效。我该怎么办? 最佳答案 您引用的 MySQL 文档实际上比您提到的要多一些
我一直在使用 SED (Bash shell) 转义单引号问题。 我需要做 $cfg['Servers'][$i]['password'] = ''; 进入 $cfg['Servers'][$i]['
需要将'替换为\'但这就是我得到的: >>> s = "It's nice to have an example" >>> s.replace("'", "\\'") "It\\'s nice to
我在处理连接字符串中的 ' 字符时遇到问题。 Entity Framework 抛出异常说: Format of the initialization string does not conform
我遇到了一个非常奇怪的问题,我无法设置 Content-Security-Policy 所需的单引号。我假设我运行的是旧版本的 ingress,它仅在我禁用并重新启用它 (microk8s) 后才得到
插入带有撇号的值的正确 SQL 语法是什么? Insert into Person (First, Last) Values 'Joe', 'O'Brien' 我不断收到错误,因为我认为
我有三列数据 selector label option list time you personally
我使用 Java Pattern 类将正则表达式指定为字符串。 举个例子我喜欢成为蜘蛛侠:“彼得·帕克” 应将蜘蛛侠和“Peter Parker”列为单独的标记。谢谢 try { Buffe
我正在尝试删除标记 ' (单引号)但我不知道如何。 我在做delm \'但它不起作用。我也尝试了我能想到的所有组合。 我意识到这更像是一个 Vim 脚本问题,但我在任何地方都找不到。 最佳答案 为什么
如何禁用红色突出显示的特定实例。 我尝试在单引号前输入转义符,但没有成功。我确信单引号导致了红色突出显示,因为当我删除它时,它就会消失。 代码如下: import React from 'react'
我需要输出单引号 (')。它必须是单引号而不是 ',因为这是用于向 jquery 函数提供数据的字符串的一部分。 我使用 C# 循环遍历一个对象来构建一个字符串 "var data = [['Item
我正在尝试: "l'ape"); ?> var my_javascript_object = jQuery.parseJSON(''); 我收到此错误“未捕获的语法错误:意外的标识符”。问题是
我的问题是关于传递给方法验证的“add\”反斜杠单引号,该反斜杠单代码有什么用? document.writeln('\',\'N\'))>'); 最佳答案 欢迎来到堆栈溢出。 反斜杠告诉代码这不是引
我要执行命令: xcodebuild -exportArchive -exportFormat IPA -archivePath myApp.xcarchive -exportPath myApp.i
我有一个字符串,里面有一个 ': example link text 不幸的是,这似乎不起作用。 Firebug 提示“SyntaxError:参数列表后缺少 )”,您可以看到 HTML 实体已被 '
据我所知,'mars%22%3A%22' 和 "mars%22%3A%22" 是等效的,因为没有任何内容被转义. 我创建 javscript 书签已经有一段时间了。有一次,当按原样粘贴到 Chrome
我是一名优秀的程序员,十分优秀!