【发布时间】:2019-11-22 09:40:44
【问题描述】:
我有这个代码作为输入(我会为多个数据帧多次这样做,所以我的代码在循环中)
v="S"
df_a = pd.DataFrame({ 'Type1': ['A'],'Type2': ['B'],'Type3': ['C'],'Type4': ['D']})
df_a
Output :
Type1 Type2 Type3 Type4
0 A B C D
我需要这个
Output :
V Col Val
0 S Type1 A
1 S Type2 B
2 S Type3 C
3 S Type4 D
谢谢
【问题讨论】:
-
df_a.melt(var_name='Col', value_name='Val').assign(V=v)
标签: python pandas dataframe reshape