我想复制使用Python和pandas链接的情节。你知道吗
下面是数据框。你知道吗
df = pd.DataFrame(
{"Sex":["Male"]*8+["Female"]*6,
"Metabolic Rates":[525.8,605.7,843.3,1195.5,1945.6,2135.6,2308.7,
2950,727.7,1086.5,1091,1361.3,1490.5,1956.1]})
我试图用matplotlib的错误条来实现它,但似乎不起作用。你知道吗
import numpy as np
x = [1,2,3,4,5,6,7,8]
dy = 894.372699158466
y = df.loc[df["Sex"]=="Male"]["Metabolic Rates"]
plt.errorbar(x, y, yerr=dy, fmt='o');
我只得到这个图:
你可以这样画:
当然,更多的格式是可选的。例如,绘制红色箭头需要
plt.annotate
。你知道吗为了充分使用
pandas
功能,我建议重新格式化df
。使用列或索引是在pandas中聚合数据的一种很好的方法。 例如,您可以这样格式化您的df:(我想使用
groupby
或aggregate
还有一种更简单的方法。)现在您可以很容易地获得所有具有
df.std()
和df.mean()
的列所需的信息,如std
和mean
。也可以使用前端。你知道吗相关问题 更多 >
编程相关推荐