创建示例数据框
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df = pd.DataFrame(np.random.randint(0,10,size=(8, 2)), columns=list('AB'))
df["B"] = ["Apple","Mango","Apple","Apple","Mango","Apple","Mango","Apple"]
我将DF分组在“ B”列上,并绘制“ A”列的平均值。
df.groupby("B")["A"].mean().plot()
plt.show()
情节正常。但是,有没有一种熊猫方法来标记图中的点。例如,如果在B上分组的均值(col_A)(B =苹果)=> 10,则可以用该值标记点(在这种情况下为10)