【发布时间】:2018-12-11 21:55:22
【问题描述】:
我有以下代码(Python 2.7):
response2 = requests.get(...)
sample_object = pd.DataFrame(response2.json())['results'].to_dict()
这会从我的 DataFrame 中创建一个 dict,我正在从中创建一个 Json 但是它没有排序:
如何按键排序?意思是isGift 在ShippingAddress_city 之前等等...
我看到了像this 这样的私人答案,但我无法在我的代码中做到这一点......
也试过to_dict(into=ordered),但没有任何反应。
有没有一种简单的方法可以从一开始就对其进行排序?或者我必须仅在创建后对其进行排序,如果是,我该怎么做?
【问题讨论】:
标签: python python-2.7 pandas dictionary