Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
anurnair opened this issue Jul 12, 2018 · 0 comments

Comments

@anurnair
Copy link

anurnair commented Jul 12, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant