ValueError: invalid literal for int() with base 10: '405,000'
the code is as follows :
for d in csv.DictReader(open(c_name + '.csv'), delimiter=','):
global d_value
d_value = int(d['Debt Value'])
405,000
isn't a valid int
. You either need to remove that comma:
d_value = int(d['Debt Value'].replace(',', ''))
import locale
# You might need to set a locale
# locale.setlocale(locale.LC_ALL, '')
d_value = locale.atoi(d['Debt Value'])
It looks like you have a comma in your value, which is why you're seeing the error. You may want to sanitize your numbers by doing something like this:
d_value = int(d['Debt Value'].replace(",", ""))
While you're at it, it's a good idea to close your files when you're done with them. You can use a with statement to make sure it will close after your block.
with open(c_name + ".csv") as csvfile:
for d in csv.DictReader(csvfile, delimiter=','):
global d_value
d_value = int(d['Debt Value'].replace(",", ""))