在python中,我想根据索引值加入/合并2个CSV文件。另一个CSV。
ex:csv 1:
Index topic subject
1115 fcfs Operating System
1923 dml Database Management System
835 jdbc Object_oriented_programing
1866 joints Database Management System
CSV 2:
Index Questions
180 When an object is seen from front..
1115 Case in which fcfs is the best algo
959 How does the scheduler know the time..
输出CSV:
Index topic Subject Questions
1115 fcfs Operating System Case in which..
请帮助我在Python中编写代码
这是Pandas的理想用例
import pandas as pd
csv_1 = pd.read_csv('csv1.csv')
csv_2 = pd.read_csv('csv2.csv')
merged = csv_1.merge(csv_2, on='Index')
merged.to_csv('output.csv', sep=',', header=True, index=False)
您可以在此处阅读有关打开文件并在此处合并的更多信息。