我正在使用两种CSV:program_templates.csv和courses.csv。每个CSV都有多个列,但都包含一个相同标题的列“ CC-ID”。我需要一个函数来读取courses.csv,并在program_templates.csv中查找CC-ID,然后将program_templates.csv中的“ template_code”附加到courses.csv文件中。很抱歉,因为我是菜鸟。
courses.csv
-------------------
Row, CC-ID, Title, Term,
1, BUS101, Business-101, Fall 2019,
2, ENG101, English-101, Fall 2019,
3, HIS101, History-101, Fall 2019,
4, COM101, Communi-101, Fall 2019,
5, COM102, Communi-102, Fall 2019,
program_templates.csv
-------------------
CC-ID, template,
BUS101, temp_bus,
COM102, temp_com,
ENG101, temp_eng,
HIS101, temp_his,
COM101, temp_com,
我尝试了栈中提到的几个不同选项,并对df merge
和```join````函数感到更加困惑。
courses-w-IDs.csv
-------------------
Row, CC-ID, Title, Term, template,
1, BUS101, Business-101, Fall 2019, temp_bus,
2, ENG101, English-101, Fall 2019, temp_eng,
3, HIS101, History-101, Fall 2019, temp_his,
4, COM101, Communi-101, Fall 2019, temp_com,
5, COM102, Communi-102, Fall 2019, temp_com,