我的数据框如下所示:
Year Scenario Type_1 US China India France Type_2 US India Germany 0 2010 A Type_1 100 101 102 100 Type_2 50 51 52 1 2011 A Type_1 102 103 104 102 Type_2 52 53 54 2 2010 B Type_1 99 100 101 99 Type_2 49 50 51 3 2011 B Type_1 101 102 103 101 Type_2 51 52 53
我想将列转换为变量。 是否有可能使数据框如下所示?
Year Scenario Type Country Value 0 2010 A Type_1 US 100 1 2010 A Type_1 China 101 2 2010 A Type_1 India 102 3 2010 A Type_1 France 100 4 2011 A Type_1 US 102 5 2011 A Type_1 China 103 6 2011 A Type_1 India 104 7 2011 A Type_1 France 102 8 2010 B Type_1 US 99 9 2010 B Type_1 China 100 10 2010 B Type_1 India 101 11 2010 B Type_1 France 99 12 2011 B Type_1 US 101 13 2011 B Type_1 China 102 14 2011 B Type_1 India 103 15 2011 B Type_1 France 101 16 2010 A Type_2 US 50 17 2010 A Type_2 India 51 18 2010 A Type_2 Germany 52 19 2011 A Type_2 US 52 20 2011 A Type_2 India 53 21 2011 A Type_2 Germany 54 22 2010 B Type_2 US 49 23 2010 B Type_2 India 50 24 2010 B Type_2 Germany 51 25 2011 B Type_2 US 51 26 2011 B Type_2 India 52 27 2011 B Type_2 Germany 53
答案 0 :(得分:3)
一个棘手的问题,因为您的名称在各列中重复。
default_avatar = forms.ChoiceField()