I have a script that parses data from a csv file. The following line is giving me problems:
countData.append([timeStamp,int(my_csv[row][5])])
It gives me the following error:
ValueError: invalid literal for int() with base 10: '808.666666666667'
The line of the csv file is as follows:
2013-06-12 15:09:00,svcName,0,0,10,808.666666666667
I have tried running int(808.666666666667)
in a python prompt and it works fine.
invalid literal for int() with base 10. The error message invalid literal for int() with base 10 would seem to indicate that you are passing a string that's not an integer to the int() function . In other words it's either empty, or has a character in it other than a digit.
The Python ValueError: invalid literal for int() with base 10 error is raised when you try to convert a string value that is not formatted as an integer. To solve this problem, you can use the float() method to convert a floating-point number in a string to an integer.
From help on int
:
int(x, base=10) -> int or long
If x is not a number or if base is given, then x must be a string or Unicode object representing an integer literal in the given base.
So, '808.666666666667'
is an invalid literal for int
for any base
, use:
>>> int(float('808.666666666667' ))
808
int(808.666666666667)
runs fine because you're passing a float to it, not a string literal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With