使用多索引控制数据帧子批次分组

2024-07-07 07:41:09 发布

您现在位置:Python中文网/ 问答频道 /正文

与:

seq   = range(1,10)
rep   = range(1,3)
names = ["marco", "marcee"]
cols  = {}

cols["time"]   = [aTime+x*aMinute for x in seq for y in names]
cols["person"] = [y for x in seq for y in names]
cols["points"] = [np.log(x+y) for x in seq for y in rep]
cols["fish"]   = [np.log2(x+y) for x in seq for y in rep]

multiTSDF = pd.DataFrame(data=cols).set_index(["time", "person"])
multiTSDF.unstack("person")

当调用plot()时,我得到一个绘图,x是时间,y是fishpoints的值。如果我设置subplots=True,那么我得到四个图。如何获得两个绘图,一个是fish绘图,另一个是points绘图,其中每个绘图包含两个人各自的一行


Tags: in绘图fortimenamesnprangeseq