python - 将json数据存储到熊猫中
问题描述
在这里,我正在定义我的 pandas DF
df = pd.DataFrame(columns=['ColA',
'ColB',
'ColC',
'ColD'
]
然后使用我想要的数据对 json 响应进行休息请求
..building json requst
js = request.json()
return_list = js["result"]["data"] #json list
然后我使用它来将该数据添加到我的数据框中
#loop through returned data
for id in return_list :
line = []
#looping through all elements for each data point
for x in return_list[id]:
line.append(torrents[id][x])
df.loc[df.size] = line
但是,最后的代码块非常慢..我该如何优化它?
这是一个如果可行的话我可以做什么的例子
df = pd.DataFrame(columns=['a',
'b',
'c',
'd'
])
x = [[1,2,3,4],[1,2,3,4]]
df.append(x, ignore_index=True)
#however, df will be empty
解决方案
推荐阅读
- javascript - Javascript文件在symfony twig中不起作用
- python - 使用 python boto3 连接到 aws 时出现挂起问题
- javascript - 试图获取 if 语句以确定插件应用程序的“上下文”
- ios - 显示视图时在 NavigationLink 上隐藏人字形/箭头,SwiftUI
- excel - 如果单元格显示0但有公式,如何删除行?
- javascript - Google Sheets Script - 将范围作为函数参数传递
- reactjs - 我可以在 react-js 应用程序中使用不同的域吗
- oauth-2.0 - Java 中 OIDC 隐式代码流的示例代码
- syntax - 什么是 Z3Py FreshBool() 函数?
- javascript - 有没有办法将文本文档写入屏幕并在文档中搜索特定单词并打印出这些单词