I read in a CSV file for linking to a .shp file.
All the variables that are just numbers came in as text.
How do I change the text variables to numeric in QGIS?
I read in a CSV file for linking to a .shp file.
All the variables that are just numbers came in as text.
How do I change the text variables to numeric in QGIS?
I once had the same question. The answer is that you put a file in the same folder with the ending csvt. For example your file name is xyzdata.csv you add the file xyzdata.csvt
This one you can edit with editor for example. And in it you set the data type like this. "Integer","String","Integer","Integer","String","Real"
Integer is now the variable for the first column, string for the second and so on... Make sure the files are named identically.
Edit: See here too if needed: http://underdark.wordpress.com/2011/03/07/how-to-specify-data-types-of-csv-columns-for-use-in-qgis/
Rather than messing with the input file, trying to get everything picture perfect, just use the field calculator to convert the text to a number / real. See the examples below:
Instead of loading the .csv using Add vector layer, use the Delimited Text layer tool. It will try to detect the most fitting data type for each column.
For more details see the QGIS user guide.
MMQGis caused this problem, and, as it turns out, it can fix it to.
Once you've joined your Shapefile & CSV Data, use MMQGis's Modify > Text to Float tool.
As usual, it leaves a trail of junk intermediate shapefiles but what else is new
In QGIS 3.x a common error source is to choose the wrong decimal separator. Check or Uncheck the box "Decimal separator is comma" before loading your CSV into QGIS:
Another alternative in case of large datasets to be managed and obviously time consuming to to proceed with the field calculator (without looping) or within a text editor : - save your data as CSV + XY + variable for the joint with our polugone shapefile - upload your CSV with the plug in (import csv) then save as shapefile (point) - then close q gis - back to the folder with the shapefile point, duplicate the corresponding dbf table / rename - open Qgis - upload the new dbf and join to shapefile (polygone features)
One stone, two pigeons : you have potentally 1) a shapefile point with all the data and all the possibility of represention 2) and independant shapefile with dbf table joined (editable !) linked to polygone for thematic cartography
This is a bit rude , but quite straightforward ...
bs_epidemio
.csv
file into an editable format, it does not address the original question of how to convert an attribute value from a text to a number. While it is important to have quality, focused questions, it is equally critical that the answers to those questions be as focused and relevant as possible to what was asked originally.
– Get Spatial
Sep 23 '12 at 0:37