我有下面的dataframe,我正在尝试在分组数据之后绘制值和误差线
import pandas as pd
from pprint import pprint
def classify_data():
race = ['race1','race1','race1','race1','race2','race2','race2', 'race2']
qualifier = ['last','first','first','first','last','last','first','first']
participant = ['rat','rat','cat','cat','rat','dog','dog','dog']
avgsteps = ['223','321', '445', '165', '216', '127', '122', '214']
measureerror = ['0.02', '0.01', '0.01', '0.05', '0.02', '0.01', '0.01', '0.05']
id = ['a', ' b', 'c', 'd', 'e', 'f', 'g', 'h']
df = pd.DataFrame(
{'race': race,
'qualifier': qualifier,
'participant': participant,
'avgsteps' : avgsteps,
'measureerror': measureerror
}
)
我想将数据分组如下:
race qualifier participant avgsteps measureerror id
0 race1 first rat 321 0.01 b
1 race1 first cat 445 0.01 c
2 race1 first cat 165 0.05 d
3 race2 first dog 122 0.01 g
4 race2 first dog 214 0.05 h
我打算为每个种族类型创建单独的绘图。
例如,race 1
的绘图,其id位于x轴上,avgsteps
和
y轴上measureerror
的误差线。我想根据
participant
类型
首先,我试着
df2 = (df.groupby(['race', 'qualifier'])
)
这将返回一个对象,我不知道如何继续
编辑:
df = df[df.qualifier.str.contains('first')]
给予
1 race1 first rat 321 0.01 b
2 race1 first cat 445 0.01 c
3 race1 first cat 165 0.05 d
6 race2 first dog 122 0.01 g
7 race2 first dog 214 0.05 h
但是,我不知道如何直接使用groupby
我想就如何进行征求意见
我没用groupby就找到了另一个选择
唯一的问题是误差线和数据点的颜色不同。有没有关于如何为值和误差条指定相同颜色的建议
我也很高兴知道其他的方法
相关问题 更多 >
编程相关推荐