For reading csv files, it is easier to use csv:DictReader (or pandas with pandas.read_csv).
from csv import DictReader
reader = DictReader(open("xxxx.csv"), delimiter=',')
The result is a Python dictionary with the values in the first row used as the fieldnames/keys
Example
reader = DictReader(open("my.csv"), delimiter=',')
for row in reader:
print row
{'y': '89857.66933', 'x': '205552.62867', 'z': '222.2'}
{'y': '89117.14521', 'x': '203039.279', 'z': '232.18'}
{'y': '89312.90303', 'x': '205228.00325', 'z': '216.11'}
{'y': '88530.96348', 'x': '203384.44062', 'z': '213.41'}
{'y': '89202.89231', 'x': '204949.65734', 'z': '226.02'}
And you only need one loop (and not two) to create the shapefile (you can also use Fiona as in GitHub Gist: gistfile1.py of Sean Gillies)
import shapefile as shp
filename = 'test'
w = shp.Writer(shp.POINT)
w.field('Longitud','F',10,8)
w.field('Latitud','F',10,8)
w.field('altitud','F',10,8)
reader = DictReader(open("my.csv"), delimiter=',')
# writing shapefile
for i in reader:
w.point(float(i['x']),float(i['y']))
w.record(float(i['x']),float(i['y']),float(i['z']))
w.save(filename)
now write the prj file (Pyshp: Creating a .prj file):
# writing prj file
prj = open("%s.prj" % filename, "w")
epsg = 'PROJCS["Belge 1972 / Belgian Lambert 72",GEOGCS["Belge 1972",DATUM["D_Belge_1972",SPHEROID["International_1924",6378388.0,297.0]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.017453292519943295]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["central_meridian",4.367486666666666],PARAMETER["latitude_of_origin",90.0],PARAMETER["standard_parallel_1",51.166667233333335],PARAMETER["false_easting",150000.013],PARAMETER["false_northing",5400088.438],PARAMETER["standard_parallel_2",49.83333389999999],UNIT["m",1.0]]'
prj.write(epsg)
prj.close()
Control of the resulting shapefile with Fiona
import fiona
# read the shapefile
c = fiona.open('test.shp')
# schema of the shapefile
c.schema
{'geometry': 'Point', 'properties': OrderedDict([(u'Longitud', 'float:10.8'), (u'Latitud', 'float:10.8'), (u'altitud', 'float:10.8')])}
# crs of the shapefile
c.crs
{u'lon_0': 4.367486666666666, u'ellps': u'intl', u'y_0': 5400088.438, u'no_defs': True, u'proj': u'lcc', u'x_0': 150000.013, u'units': u'm', u'lat_2': 49.83333389999999, u'lat_1': 51.16666723333334, u'lat_0': 90}
# first feature
c.next()
{'geometry': {'type': 'Point', 'coordinates': (205552.62867, 89857.66933)}, 'type': 'Feature', 'id': '0', 'properties': OrderedDict([(u'Longitud', 205552.628), (u'Latitud', 89857.6693), (u'altitud', 222.2)])}
.