IAMconsortium / pyam

Analysis & visualization of energy & climate scenarios
https://pyam-iamc.readthedocs.io/
Apache License 2.0
221 stars 115 forks source link

Algebraic operations on timeseries data between scenarios #760

Closed cheolhung closed 12 months ago

cheolhung commented 12 months ago

How do algebraic operations between scenarios with a IamDataFrame? For example, If I want to calculate the difference of primary energy between Scenario A and Scenario B, and append a new timeseries with a new scenario name in the frame, Is there any function to do it easily? (I couldn't find any help from pyam webpage)

Thanks in advance.

image

danielhuppmann commented 12 months ago

You can use the axis keyword-argument of the subtract() method (or divide() if you want to have the relative difference). See the tutorial notebook at https://github.com/danielhuppmann/ENGAGE-pyam-tutorial/ for an example.

Please close this issue if this answer was sufficient, or let me know if you need more help.

cheolhung commented 12 months ago

Thanks a million!

cheolhung commented 12 months ago

I have another issue with algebraic operations. If I use 'append=True', there is an error such as 'ValueError: Timeseries data has overlapping values:' Would you please help me fix it? Thanks in advance.

image

danielhuppmann commented 12 months ago

My guess is that you have executed this cell twice - so you already appended the date, and then try to append it again. To which pyam (rightly) raises an error that there is overlapping (duplicate) data between the already data in df and the to-be-appended data.

cheolhung commented 12 months ago

I thought the error occurred when I executed the first time. Now I see that the to-be-appended data is already in the data frame. I really appreciate your prompt reply.