'How do I fix this error in python { LAT.append(float(row[6].strip())) ValueError: could not convert string to float: '\\N' }?
I am creating a function to read in all the data from a .csv file and append each column to a list. However, when I try to convert the values in a certain column to a float, it gives me this error {LAT.append(float(row[6].strip())) ValueError: could not convert string to float: '\N'}. Here is what I am working with:
ID = []
NAME = []
ADDRESS = []
POSTAL = []
EAST = []
NORTH = []
LAT = []
LON = []
AUTH = []
# read in data
def read_data():
data = pd.read_csv('Pubs in England.csv', delimiter=',')
for row in data.values:
ID.append(row[0])
NAME.append(row[1])
ADDRESS.append(row[2])
POSTAL.append(row[3])
EAST.append(row[4])
NORTH.append(row[5])
LAT.append(float(row[6].strip()))
LON.append(float(row[7].strip()))
AUTH.append(row[8])
The LAT list is for all the latitude values in the .csv file and the LON list is for all the longitude values in the .csv file. Everything else works as intended.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
