我有一个类似的数据框:
import pandas as pd
df = pd.DataFrame({'source': {0: u'1:19374802:19380807',
1: u'2:4608900:4614600',
2: u'5:14175176:14182011',
3: u'2:4608900:4614600',
4: u'5:14171600:14173742'},
'target': {0: u'2:4608900:4614600',
1: u'5:14175176:14182011',
2: u'2:4608900:4614600',
3: u'5:14171600:14173742',
4: u'2:4608900:4614600'}})
source target
0 1:19374802:19380807 2:4608900:4614600
1 2:4608900:4614600 5:14175176:14182011
2 5:14175176:14182011 2:4608900:4614600
3 2:4608900:4614600 5:14171600:14173742
4 5:14171600:14173742 2:4608900:4614600
数据源于多对多关系的多次迭代。在数据中,Source:Target == Target:Source
。因此,关系会重复(例如,第1行和第2行)。
我希望水平排序:
source target
0 1:19374802:19380807 2:4608900:4614600
1 2:4608900:4614600 5:14175176:14182011
2 2:4608900:4614600 5:14175176:14182011
3 2:4608900:4614600 5:14171600:14173742
4 2:4608900:4614600 5:14171600:14173742
因此可以删除重复项。
答案 0 :(得分:1)
我会使用NumPy来做,因为它可能会更快:
return (
<div>
<div>Response - {this.state.data.content}</div>
<div>id - {this.state.data.id}</div>
</div>
);
答案 1 :(得分:0)
下面:
df.apply(sorted, axis=1)