I want to convert a number written in CSV into a decimal with float (), but I get an error.
I wrote the code below.
import csv from getenc import getEncode CSVFILE = 'D: \\ Desktop \\ recipe_amazu.csv' # Can read even if the character code is unknown enc = getEncode (CSVFILE) with open (CSVFILE, 'r', encoding = enc) as csvfile: csv_reader = csv.reader (csvfile, delimiter = ',', quotechar = '"') for row in csv_reader: CSVtext = row for i in range (2, len (CSVtext), 2): if i<21: print (CSVtext [i + 1]) flo = float (CSVtext [i + 1]) print (flo)
The execution result is as follows.
Traceback (most recent call last): 300 File "C:/file location/otamesi2.py", line 19, in<module> flo = float (CSVtext [i + 1]) 300.0 50 ValueError: could not convert string to float: 50.0
Answer # 1
I'm not sure because the order of output is fluctuating, but I feel like an empty string goes over the float.
Check if there is a problem with the loop (whether it is a loop that refers to an empty string).
- [c] i want to convert a string to a number, but it doesn't work
- convert integer number to string year/month display in java
- converting time sequence of number string using python
- swift - i want to convert an int to a string with a specified number of digits padded with spaces
- python - could not convert string to float error
- how can i convert a number to a string and concatenate it in c++?
- python - i want to extract the character string excluding the blank characters at the end of the line
- unity - cannot convert float type to string type
- python - i want to display the individual number while keeping the clustering result in matplotlib
- python number aggregation method csv
- python - how to cycle the input string
- python - create a new column by counting the number of elements in the column
- python 3x - a program that outputs the number 1 in a 3-digit integer
- i want to put the string b in the list as [, b, ] [python]
- c# - i want to convert a string type to a class and attach it to an object
- python 3x - python3 i want to convert hexadecimal numbers to array components
- python - i want to limit the number of images to be extracted
- python - on the "c-proportion number series" of the 3rd algorithm skill test
- python - how to simplify complex expression of complex number of primary array in numpy to "real number + complex number&qu
- python - change the number of training data with mnist
- python - how to remove a list from a tuple and store only the value
- http error 503: service unavailable when doing amazon scraping with python
- python - i want to simplify the program that sequentially retrieves from the list
- python - regarding the problem that tries to decompose a string apostrophe using a dictionary but fails
- python - common behavior for everything in django
- python - i want to split one array into two without duplication
- about the problem that float subtraction does not work in numerical calculation in python
- python - something went wrong in the jupiter lab
- python - how to deal with error when converting pandas datetime type
- i want to read python time series data while shifting by 1 day