How to transform and cummulate data in python
I think the following lines should give the output you are looking for:

# Create pivot table
df = pd.pivot_table(df, values="value", index="country", columns="year")
# Calculate cumulative sum and forward fill NaN
df = df.cumsum(axis=1).fillna(method="ffill", axis=1)
# Reshape data back into long format
df = df.reset_index().melt("country")


I first create a pivot table with the countries in the rows and the years in the columns to get all the years that may be missing in the long format data. I then calculate the cumulative sum, after which I forward fill the values over the columns. To finally reshape the data back into the original long format I reset the index and melt the dataframe with the country as the id column. Given your input, this returns the following dataframe:

   country  year  value
0    JAPAN  1999   10.0
1    KOREA  1999    NaN
2      USA  1999    NaN
3    JAPAN  2000   10.0
4    KOREA  2000   15.0
5      USA  2000   20.0
6    JAPAN  2001   10.0
7    KOREA  2001   15.0
8      USA  2001   33.0
9    JAPAN  2002   40.0
10   KOREA  2002   15.0
11     USA  2002   33.0