Python, using .txt file to create a new chart. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Python, using .txt file to create a new chart.

Hi guys :) I wanted to create a chart that will use the data from my .txt file (spectral analysis) but there is an error that I don't know how to delete. 'ValueError: invalid literal for int() with base [number of the code line]: 'd>>ż43' In my .txt the first line of the value x is 43,066406. I don't know how to deal with this. I've just wanted to create a chart that x can be frequency and y can be dB. Please, help me.

28th Dec 2018, 1:54 AM
Mokka
Mokka - avatar
4 Answers
+ 3
The error clearly says 'invalid literal for int() with base 10 ' and its bcz of that comma in "43,065406". >> int('1234') Will result in 1234 But >> int('1,234') It will give you a ValueError coz string can only be converted into int type if it consists of only numeric characters.
28th Dec 2018, 2:42 AM
Шащи Ранжан
Шащи Ранжан - avatar
+ 2
No need to convert those into whole numbers. Just use '.' for decimal instead of comma and use float() instead of int() and you're good to go.
28th Dec 2018, 12:00 PM
Шащи Ранжан
Шащи Ранжан - avatar
+ 1
Thank you :)
28th Dec 2018, 2:13 PM
Mokka
Mokka - avatar
0
So if I want to get this chart I must change all the numbers into whole numbers? But is there another way to get more accurate chart?
28th Dec 2018, 11:42 AM
Mokka
Mokka - avatar