[英]Easiest way to plot data from JSON with matplotlib?
So I have some data in json format, here's a snippet: 所以我有一些json格式的数据,这里是一个片段:
"sell": [
{
"Rate": 0.001425,
"Quantity": 537.27713514
},
{
"Rate": 0.00142853,
"Quantity": 6.59174681
}
]
What's the easiest way to access Rate and Quantity so that I can plot it in Matplotlib? 访问速率和数量的最简单方法是什么,以便我可以在Matplotlib中绘制它? Do I have to flatten/normalize it, or create a for loop to generate an array, or can I use pandas or some other library to convert it into matplotlib friendly data automatically?
我是否必须展平/标准化它,或者创建一个for循环来生成一个数组,或者我可以使用pandas或其他一些库将它自动转换为matplotlib友好数据吗?
I know matplotlib can handle inputs in a few ways 我知道matplotlib可以通过几种方式处理输入
plt.plot([1,2,3,4], [1,4,9,16])
plt.plot([1,1],[2,4],[3,9],[4,16])
The simpliest is DataFrame
constructor with DataFrame.plot
: 最简单的是
DataFrame
构造函数和DataFrame.plot
:
import pandas as pd
d = {"sell": [
{
"Rate": 0.001425,
"Quantity": 537.27713514
},
{
"Rate": 0.00142853,
"Quantity": 6.59174681
}
]}
df = pd.DataFrame(d['sell'])
print (df)
Quantity Rate
0 537.277135 0.001425
1 6.591747 0.001429
df.plot(x='Quantity', y='Rate')
EDIT: 编辑:
Also is possible use read_json
for DataFrame
. 也可以使用
read_json
进行DataFrame
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.