import pandas as pd answer = [] questioin = [] with open("/home/zhangxj/WorkFile/LCA-GPT/QA/answer.txt","r",encoding="utf-8") as f: text = f.readlines() for line in text: str = line.strip() answer.append(str) with open("/home/zhangxj/WorkFile/LCA-GPT/QA/ques.txt","r",encoding="utf-8") as f: text = f.readlines() for line in text: str = line.strip() questioin.append(str) df = pd.DataFrame({"question":questioin,"answer":answer}) print(df.head()) df.to_csv("/home/zhangxj/WorkFile/LCA-GPT/QA/QA.csv",index=False)