rnelsonchem/simpledbf

Is there any way to convert all columns in dbf files to string data type.

Opened this issue · 0 comments

I have a dbf file where default date is coming as '00000000'. Is there any way to convert all columns into string before changing the format. My current code is-

import simpledbf as sdbf 
import pandas as pd
import sys
import os
path = "path\\of\\directory\\"
for file in os.listdir(path):
    if file.endswith(".DBF"):
        print(file)
        dbf1 = sdbf.Dbf5(path+file)
        df = dbf1.to_dataframe()
        df.to_csv(path+file[:-4]+'.TXT', header='0', index=None, sep='|', mode='a');

With above code I am getting error as : "ValueError: year 0 is out of range"

I am looking for below solution:

  1. Either convert data types for all columns into string before changing the format
    OR
  2. Replace the invalid date value to some default date like 01/01/1900.

@rnelsonchem any ideas how can I handle this issue.