如何连接2个数据框,使行具有相同的索引

时间:2019-09-03 09:00:53

标签: python pandas dataframe merge concatenation

enter image description here我有2个数据框,我想与它们保持df1列的顺序一致:

df1:
index   unnamed:0   unnamed:1      unnamed:393    unnamed:395
 0       nan           1       ...     394           396 
 1       0            BB               CC            DD


df2:

    index     Service
     220      ABC
     222      ABB
     394      CC
     396      DD
     ....

the output should be like:
df3:

     index 
       0      394    396  
       1      394    396
       2      CC     DD
       3      CC     DD

如果我只是制作df3=pd.concat([df1,df2]),它只会在整个df 1列表的末尾添加df2 使用df3=pd.concat([df1,df2], axis=1, ignore_index=True)时几乎相同 我认为多索引存在一些问题,但不知道该输入什么。 谢谢

1 个答案:

答案 0 :(得分:0)

您可以使用func tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath) { let cell = tableView.cellForRow(at: indexPath) cell!.contentView.backgroundColor = .red } func tableView(_ tableView: UITableView, didUnhighlightRowAt indexPath: IndexPath) { let cell = tableView.cellForRow(at: indexPath) // Add timer to be able see the effect Timer.scheduledTimer(withTimeInterval: 0.2, repeats: false) { (_) in cell!.contentView.backgroundColor = .white } }
这样会产生如下结果:
enter image description here
该文档为here
有关熊猫中各种合并操作的更多信息,您还可以选中this