I have some csv lookup tables which are too heterogeneous for ordinary join so I want to process them in PyQGIS. However the csv files have no geometry column whatsoever. If used as QgsVectorLayer
the layer ends up empty:
uri='path/to/csv/file.csv?delimiter=;'
csvLyr = QgsVectorLayer(uri, "csvLayer", "delimitedtext")
QgsProject.instance().addMapLayer(csvLyr) #throws 'source data cannot be found'
csvLyr.getFeature(0) #returns a non callable QgsFeature
Is there a way in PyQGIS to query and manipulate non-spatial csv data just like any other vector data (respectively just like in the GUI) or am I required to use the csv module/another Python library?
I am using Python/PyQGIS 3 in QGIS 3.6. The csv files all have header rows.
uri
? Make sure it begins withfile:///
so that your path looks something like:uri = 'file:///C:/Users/You/Desktop/points.csv?delimiter=;'