I've created the shapefile and can manually enter in all the attributes to come in fine, but when I call it any other way (which I will need to do), the values for the floating types appear as NULL, even after converting to str or int.
When I print dato.iloc[0].tolist()
, it spits out the first row of data as a list, and looks as follows: ['1', '1', '31isk', 4613427, 413588.12200000003, 1.19, 'sand'].
If I have feat.setAttributes(dato.iloc[0].tolist())
, all values except for the three floats come in fine. If I print and copy the resulting string into feat.setAttributes, it will add the attribute perfectly okay. This is only a quikc fix and not possible when there are hundreds of more attributes to add.
So again, this does NOT work: dato.iloc[0].tolist()
But this DOES work: feat.setAttributes(['1', '1', '31isk', 4613427, 413588.12200000003, 1.19, 'sand'])
This is all done within PyCharm. Fields are as follows (Northing, Easting, and Altitude all appear NULL):
layerFields = QgsFields()
layerFields.append(QgsField('Transect', QVariant.String))
layerFields.append(QgsField('PointNumber', QVariant.String))
layerFields.append(QgsField('SubClass', QVariant.String))
layerFields.append(QgsField('Northing', QVariant.String))
layerFields.append(QgsField('Easting', QVariant.String))
layerFields.append(QgsField('Altitude', QVariant.String))
layerFields.append(QgsField('Notes', QVariant.String))
I've tried setting QVariant to int and converting the float values to ints but still nothinng.
QVariant.Double
for yourQgsField
Northing
,Easting
,Altitude
? Did you also tried to do[type(i) for i in dato.iloc[0].tolist()]
to be sure of type of each element in your list (sometimes what you see is not what you visually think it is)?item
method like described at stackoverflow.com/questions/9452775/… Normally, the following code[i.item() if isinstance(i, numpy.generic) else i for i in dato.iloc[0].tolist()]
should work to cast all numpy objects to native Python types. I used in the previous expressionnumpy.generic
but it can benp.generic
depending if you've done numpy import withimport numpy
orimport numpy as np