I have this kind of pandas.DataFrame. "a","b" are conditions when getting "x" and "y".
df = pd.DataFrame([[10,20,0,.1], [10,20,1,.5], [100,200,0,.33], [100,200,1,.11]], columns=["a", "b", "x", "y"])
df
I need to plot line charts of (x,y) colums with respect to the same condition. The expected result plot is:
Of course, this image is manually given by the following code:
pd.DataFrame([[0,.1],[1,.5]]).plot(kind="line", x=0, y=1, style="-", legend=None, title="a: 10, b: 20")
plt.xlabel("x")
plt.ylabel("y")
plt.figure()
pd.DataFrame([[0,.33],[1,.11]]).plot(kind="line", x=0, y=1, style="-", legend=None, title="a: 100, b: 200")
plt.xlabel("x")
plt.ylabel("y")
My question is how to dynamically make plots like above when getting a dataframe including condition columns, x and y.
Update
Column names are fixed. However, values of condition columns is dynamically changed. So, I can not use the values 10, 20, 100, 200.
Update2
If I have the below "filter_with_a_and_b" method, I think the problem solved:
def filter_with_a_and_b(df, a_b):
# how to implement?
a_b_list = df.drop_duplicates(["a","b"])
new_df_list = filter_with_a_and_b(df, a_b)
for idx, df in enumerate(new_df_list):
df.plot(title=a_b_list[idx])