-
Notifications
You must be signed in to change notification settings - Fork 91
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
Value Error: could not convert string to float #29
Comments
I have my way to solve this problem. You can change the source code in field_parser.p.
It's my first time to answer question, I'm so sorry my English is so poor, and I don't know how to indent code. I hope my answer can solve your problem. If you have any question, you can contact me. |
I know this is an old thread but I just encountered this issue while working on migrating a legacy database. I checked and the legacy software simply interprets these You could use a custom parser class to override the from dbfread import DBF, FieldParser
class CustomFieldParser(FieldParser):
def parseN(self, field, data):
"""Parse numeric field (N)
Returns int, float or None if the field is empty.
"""
# In some files * is used for padding.
data = data.strip().strip(b'*')
try:
return int(data)
except ValueError:
if not data.strip():
return None
elif data.strip() == b'.':
return None
else:
# Account for , in numeric fields
return float(data.replace(b',', b'.'))
table = DBF(filepath, parserclass=CustomFieldParser, load=True) |
Hi, you have developed an excelent package for readinf .dbf but I have had many issues reading one of them. I want to keep just 2 columns of the .dbf but first I have to load it to then read for delete columns later but at this step, I got a Value Error of one of the registers of the .dbf which is part of the columns I want to delete.
In fact, first I got a Value Error with strange characters but ,modifying the function 'parseN' it was converted that strange character to 'nz'
Thanks for helping me in this issue, I hope get your answer.
The text was updated successfully, but these errors were encountered: