saving . . . saved loadtxt() is showing ValueError. Help! has been deleted. loadtxt() is showing ValueError. Help! has been hidden .
loadtxt() is showing ValueError. Help!
Title
Question
Dear Sir/Madam,

I'm using Linux Ubuntu.

In Spoken Tutorial number 9 for Python, "Other types of plots", I'm receiving a ValueError after inserting input for loadtxt function.

Firstly, I download the Code Files for this tutorial.
"2-3/company-a-data.txt"

Then enter first input as per shown:
In [1]: cat /home/hamzak/2-3/company-a-data.txt
2.000000000000000000e+03 2.001000000000000000e+03 2.002000000000000000e+03 2.003000000000000000e+03 2.004000000000000000e+03 2.005000000000000000e+03 2.006000000000000000e+03 2.007000000000000000e+03 2.008000000000000000e+03 2.009000000000000000e+03 2.010000000000000000e+03
2.300000000000000000e+01 5.500000000000000000e+01 3.200000000000000000e+01 6.500000000000000000e+01 8.800000000000000000e+01 5.000000000000000000e+00 1.400000000000000000e+01 6.700000000000000000e+01 2.300000000000000000e+01 2.300000000000000000e+01 1.200000000000000000e+01

In [2]: year,profit = loadtxt('/home/hamzak/2-3/company-a-data.txt',dtype=type(int()))
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-2-651cfa2ff470> in <module>()
----> 1 year,profit = loadtxt('/home/hamzak/2-3/company-a-data.txt',dtype=type(int()))

/usr/lib/python2.7/dist-packages/numpy/lib/npyio.pyc\\\\r\\\\n in loadtxt(fname, dtype, comments, delimiter, converters, skiprows, \\\\r\\\\nusecols, unpack, ndmin)
846 vals = [vals[i] for i in usecols]
847 # Convert each value according to its column and store
--> 848 items = [conv(val) for (conv, val) in zip(converters, vals)]
849 # Then pack it according to the dtype's nesting
850 items = pack_items(items, packing)

ValueError: invalid literal for long() with base 10: '2.000000000000000000e+03'

I'm not sure why this is error is occurring, is there something wrong with the company-a-data.txt file?

Please advice. Thank you.




Python Other-types-of-plots 02-03 min 0-10 sec 04-09-15, 9:47 p.m. hamzak

Answers:

Dear User,

Your file contains\\r\\n.The file on the website does not have them. You probably getting this error because of\\r\\n. Without them you will get proper result.

Hope this helps,

Thank you.
05-09-15, 3:36 p.m. Trupti
Dear Trupti,

Thanks for your response.
\\r\\ does not appear on the file on the website. I'm not sure why it came up here, I've edited my question now, so as you can see now; even though I've followed all instructions correctly. The problem seems to persist.

Please advice. Thank you.

05-09-15, 11:37 p.m. hamzak
P.S=Please ignore \\\\r\\\\ if it appears anywhere in the above question, I don't know why it is appearing.
05-09-15, 11:38 p.m. hamzak

Login to add comment


Dear User,

Try with float,

year,profit = loadtxt('company-a-data.txt',dtype=type(float()))

Hope this helps,
07-09-15, 11:17 a.m. Trupti


Log-in to answer to this question.