我有下面的flask函数,在这里我想返回一个有效的json resp
modified_results = modified_results.groupby(['some_type'])
tempResult = {}
for groupName, group in modified_results:
df = group.drop(columns=['some_type'])
tempResult[groupName] = processHours(df, project_code).to_json(orient='records')
return jsonify(tempResult)
我得到了我想要的格式的响应,除了有转义字符和tempResult字典将整个数据帧作为键标签的一个对象值。你知道吗
我怎样才能像这样使用字典并转换成json:
dictObj = {key1:pd.DataFrame(), key2: pd.DataFrame()}
resp = dictObj.to_json()
return resp
提前谢谢。你知道吗
我得到了我的答案,但是tojson默默地忽略了索引值。我就是这么做的。你知道吗
index=True
参数无效。你知道吗这个问题目前似乎尚未解决
另一种解决方案是将键添加为列,并在收到响应后对其进行过滤(这不是实际的解决方案):
相关问题 更多 >
编程相关推荐