dbf转excel
学校的成绩是dbf格式的,要转excel
首先pip安装两个要用到包pandas和dbfread
pip install pandas dbfread
然后直接代码:
import dbfread
import pandas as pd
file_name = "xscj (2).dbf"
table = dbfread.DBF(file_name, encoding=\'GBK\')
data = {}
for record in table:
for field in record:
if field not in data:
data[field] = [record[field]]
else:
data[field].append(record[field])
df = pd.DataFrame(data)
df.to_excel(file_name[:-4] + ".xlsx", index=False)