students = pd.read_excel('Student_Score.xlsx',sheet_name='Students',index_col='ID')
scores = pd.read_excel('Student_score.xlsx',sheet_name='Scores',index_col='ID')
# #merge多表联合how='left'表示不管对不对,按照左边的表保留数据
# table = students.merge(scores,how='left',left_on='ID',right_on='ID').fillna(0)
# #将score的浮点类型改为整数型
# table.Score = table.Score.astype(int)
# print(table)
#join多表联合,join的多表联合没有left_on和right_on
table = students.join(scores,how='left').fillna(0)
#将score的浮点类型改为整数型
table.Score = table.Score.astype(int)
print(table)
最后
以上就是傲娇便当最近收集整理的关于pandas多表联合join及merge的全部内容,更多相关pandas多表联合join及merge内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复