1

I need to control the number of significant digits assigned to attributes of an ESRI shapefile that I need to write.

UPDATE: I was using "round()" but it did not seem to work when I checked the result in QGIS Attribute table. The "problem" may in fact be in QGIS for the representation of decimals. Compare the "Form" view and the "Table" view below: digits are rounded in one but not the other.

Form view

Table view

Matthew
  • 69
  • 6
  • Take a look at the suggestions in [this thread](http://stackoverflow.com/questions/3443687/formatting-decimal-places-in-r) – hrbrmstr Jan 14 '15 at 12:03
  • Thanks. I was rounding the data in R but in QGis it wasn't showing as such. see update for info. – Matthew Jan 14 '15 at 13:28

1 Answers1

0

Not sure if this was how the file was created but if Geopandas was used to create the shapefile, it has something to do with how geopandas / pandas represents "float" or "float64" types - i.e. precision.

I fixed this problem by not using a shapefile format when saving to_file, but Geopackage (GPKG) instead. Otherwise one will have to represent the float as a string, or use the float_format argument when saving (not sure if it works for .to_file() ) - see links below.

float64 with pandas to_csv pandas converting a float remove exponents

decoder247
  • 134
  • 2
  • 12