我正在尝试打印一个数字:
df_weight = df.groupby(['city'])['weight'].mean()
ax3 = df_weight.plot()
ax3.set_title("Weight by City");
ax3.figure.savefig("WeightCity.png")
问题是我在权重列中有很多零值,因此平均值计算是错误的。
我尝试过这个来查找"权重"值>0 并工作
weightUse = df.loc[df['weight'] >0 ,'weight']
但我不知道如何使用这些信息来打印图形。有什么想法吗?
要直接打印到 stdout,这里有一种方法:
import matplotlib.pyplot as plt
%matplotlib inline
df.query("weight > 0").groupby(['city'])['weight'].mean().plot()
plt.title("plot title")