I'm trying to stack a dataframe in python by means of using the function stack() but something is not working properly.
My dataframe has the following structure:
> BE BG CZ ...
> AT_CPA_A02 0.0706 0 0.3879 ...
> BE_CPA_A02 38.8601 0.0001 0.0233 ...
> BG_CPA_A02 0 95.2664 0. ...
> ... ... ... ...
And what I'm looking for is:
> Country Val.
> AT_CPA_A02 BE 0.0706
> AT_CPA_A02 BG 0
> AT_CPA_A02 CZ 0.3879
> ...
> BE_CPA_A02 BE 38.8601
> BE_CPA_A02 BG 0.0001
> BE_CPA_A02 CZ 0.0233
> ...
Despite of this, while using the function stack() in df = df.stack() the results is:
> Country BE. BG. CZ
> AT_CPA_A02 BE 0.0706 NA. NA.
> BG NA. 0. NA.
> CZ NA. NA. 0.3879.
> ...
> BE_CPA_A02. BE. 38.8601 NA. NA.
> BG. NA. 0.0001 NA
> CZ. NA. NA. 0.0233
> ...
While using the function with some example data it works perfectly...
Could someone help me on that? Many thanks in advance