7
อ่านไฟล์ของคู่“ key = value” ซ้ำ ๆ กันใน DataFrame
ฉันมีไฟล์ txt พร้อมข้อมูลในรูปแบบนี้ 3 บรรทัดแรกซ้ำไปซ้ำมา name=1 grade=A class=B name=2 grade=D class=A ฉันต้องการส่งออกข้อมูลในรูปแบบตารางตัวอย่างเช่น: name | grade | class 1 | A | B 2 | D | A ฉันกำลังพยายามตั้งค่าส่วนหัวและวนรอบข้อมูล สิ่งที่ฉันได้ลองไปแล้วคือ: def myfile(filename): with open(file1) as f: for line in f: yield line.strip().split('=',1) def pprint_df(dframe): print(tabulate(dframe, headers="keys", tablefmt="psql", showindex=False,)) #f = pd.DataFrame(myfile('file1') …