[英]Getting list of all columns corresponding to maximum value in each row in a Dataframe
[英]How to repeat a row for each value of its corresponding columns items
col1 | col2 | col3 |
---|---|---|
(str)1 | (str)3 | (str)34 |
(str)2 | (str)4 | (str)2 |
至
col1 | col2 |
---|---|
(str)1 | (str)3 |
(str)1 | (str)34 |
(str)2 | (str)4 |
(str)2 | (str)2 |
尝试使用melt
然后sort_values
out = df.melt('col1').sort_values('col1')#.drop('variable',1)
Out[426]:
col1 variable value
0 (str)1 col2 (str)3
2 (str)1 col3 (str)34
1 (str)2 col2 (str)4
3 (str)2 col3 (str)2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.