simpledbf
simpledbf copied to clipboard
Is there any way to convert all columns in dbf files to string data type.
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:
- Either convert data types for all columns into string before changing the format OR
- Replace the invalid date value to some default date like 01/01/1900.
@rnelsonchem any ideas how can I handle this issue.