df.groupby()后面有一个以下数据。每个元素由制表符分隔:通过数据熊猫重新展开群组
Num one two three
Alp A B
是否可以将groupby恢复为融合格式?
Col1 Col2
Num one
Num two
Num three
Alp A
Alp B
在此先感谢。
AP
df.groupby()后面有一个以下数据。每个元素由制表符分隔:通过数据熊猫重新展开群组
Num one two three
Alp A B
是否可以将groupby恢复为融合格式?
Col1 Col2
Num one
Num two
Num three
Alp A
Alp B
在此先感谢。
AP
print (df)
col1 col2 col3 col4
0 Num one two three
1 Alp A B NaN
df1 = df.set_index('col1').stack().reset_index(level=1, drop=True).reset_index(name='col2')
print (df1)
col1 col2
0 Num one
1 Num two
2 Num three
3 Alp A
4 Alp B
df2 = df.melt('col1', value_name='col2').drop('variable', 1).dropna(subset=['col2'])
print (df2)
col1 col2
0 Num one
1 Alp A
2 Num two
3 Alp B
4 Num three
'民一二three'是列? – jezrael
所以它是一列? – jezrael
是的。编辑它以提高清晰度。我已经将它加入到标签 – Arun