Skip to content
Advertisement

Dataframe, sum positive and negative value on specific date interval

here’s the context : I have 2 dataframes, one from a database that generate a one month series, and the second one is a download from another database, but on one year.

I have make a plot where df1 and df2 are subtracted, creating a filled curve between, and I force the plot on just one month, so visually it’s perfect.

But I want to plot a simple bar histogram to synthesize the filled curve with a superposed bar for positive values and a bar with negative value.

Here the plot (with a factice bar plot just to show where I want the bar plot) :

So, df1 (one month) is purple, df2 (one year) is blue, filled is the subtraction between them, and the bar should display all positive and negative values of the filled curves :

enter image description here

And, it could be great if in the bar there were the text with the summed values.

I tried this command to have the sum of the positive and negative value :

JavaScript

but the result is not usable because of the difference of series size (one month / one year). Maybe if I’m using a mask ? But not sure how to do this in this case.

Advertisement

Answer

It seem I succeeded to find a way, don’t know if it’s the better but it’s working.

Here is a part on the (very long) code. In the other part (not posted) I’m acquiring data on some webservice and fill dataframe that doesn’t have data, etc …

JavaScript

The result is here (I just make the first bar plot, to validate the code and implement it on the first part of my entire code) :

enter image description here

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement