我想编写一个函数,其中可以将多个数据帧作为 *args 传递以绘制一些图。那是这样的:
def f_plot (*args):
p = None
if args == df1:
...plot rules for df1...
p = plot.show()
elif args == df2:
...plot rules for df2...
p = plot.show()
else:
raise ValueError("No *args were passed!!!)
return p
顺便说一句,我收到以下错误:
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty(), a.bool(), a.item(), a.any() or a.all().
这些是简化的 df 示例:
df1 = {'home': [A,B,C,D,E], 'away': [F,G,H,I,J], 'score_in': [2,1,3,2,0], 'score_out': [1,3,1,0,2], ‘competition’: [highschool, university, highschool, university, MLS, university]}
df2=df1.groupby('competition').get_group('university')
对于此示例,我想创建,如果 arg 等于 df1,则在同一图中的 n 个子图关于分数,其中 n 是比赛,而如果 arg 等于可能的 df2 之一,则单个图不同于以前的。
有什么帮助吗?