Home > Software design >  Plot a lineal graph with columns diverging from main column
Plot a lineal graph with columns diverging from main column

Time:02-19

Hello I want to create a lineal graph of this Dataframe

A  B  C  D
2  1  5  7
1  4  3  1

I would like to know the way to create a line graph with this idea:

Using A as Main Colum

So I want a resulting line graph with this values

A  B  C  D
0  -1 3  5
0  3  2  0

The main idea I have is to duplicate the DF and do something like this

df2=df
df2["B"]= df2["B"]-df2["A"]
df2["C"]= df2["C"]-df2["A"]
df2["D"]= df2["D"]-df2["A"]
df2["A"]=df2["A"]-df2["A"]

df2.plot()

Do you have another way to set this graph faster?

CodePudding user response:

What about:

df2 = df.sub(df['A'], axis=0)

output:

   A  B  C  D
0  0 -1  3  5
1  0  3  2  0
  • Related