0
点赞
收藏
分享

微信扫一扫

Python读取DBF文件并保存为CSV文件的几种方法

GhostInMatrix 2022-01-09 阅读 80
python
  1. 直接读取DBF
 input=f"H:/1.dbf"
     table = DBF(input, encoding='utf-8')
        #writer.writerow(table.field_names)#写入表头
     for record in table:
          print(record)

2.以Pands读取DBF并保存

with open(out, 'w', encoding='utf-8', newline="") as f:
           data = DBF(InitailData_path, encoding='utf-8')
           df = pd.DataFrame(iter(data))
           # print(df[0])
           for i in range(len(df)):
               row = df.iloc[i].values.tolist()
               # print(row)
               csv_writer = csv.writer(f)
               csv_writer.writerow([row[3]])
               flag+=1
               print(flag)
举报

相关推荐

0 条评论