I am struggling with the following code:
import numpy as np c = np.genfromtxt('C:/path/to/file.csv', delimiter=',') # check delimiter lats = c[:,0][1:] lons = -c[1:] # remove minus if you get a mirrored result data = c[1:,1:] crs = "EPSG:4326" # change if crs is different layer = QgsVectorLayer("Point?crs=" + crs + "&field=value:double", "Layer", "memory") layer.startEditing() for i, lat in enumerate(lats): for j, lon in enumerate(lons): v = data[i][j] if not np.isnan(v): feat = QgsFeature(layer.fields()) feat["value"] = float(v) geom = QgsGeometry.fromPointXY(QgsPointXY(lon, lat)) feat.setGeometry(geom) layer.addFeature(feat) layer.commitChanges() QgsProject.instance().addMapLayer(layer)
because I want to add the CSV file with the same X and Y field coordinates.
Unfortunately, I am getting an error:
ValueError: Some errors were detected ! Line #2 (got 42 columns instead of 72)
whereas it was working for another example
I tried to change the number of columns, and fill up empty values, but the error is roughly the same.
The thread below:
didn't help me with this problem.
What is the best way for removing this error?