I am having trouble transforming a dataframe I have of latitude and longitude coordinates to the state plane projection. I've attempted to use code I found in another post but it keeps throwing "AttributeError: 'float' object has no attribute 'set_value'". Here is a link to the original code so I can properly credit it: https://stackoverflow.com/a/36871668/8754430
Here is my code
import pyproj
import numpy as np
subways_loc = pd.read_csv('subways_loc.csv')
NAD83_LI = pyproj.Proj(init = "EPSG:32118")
NYS_LIZ = pyproj.Proj(init = "ESRI:102718")
def coord_transform(df):
x = pd.Series()
y = pd.Series()
for idx, val in enumerate(df['Latitude']):
x, y = pyproj.transform(NAD83_LI, NYS_LIZ, df['Longitude'][idx], df['Latitude'][idx])
x.set_value(idx, x)
y.set_value(idx, y)
df['x'] = x
df['y'] = y
return df
subways_loc_trans = coord_transform(subways_loc)
print(subways_loc_trans.head(1))
And here is the specific error:
AttributeError Traceback (most recent call last)
<ipython-input-103-a13e9199a9d5> in <module>()
11 print(x, y)
12
---> 13 subways_loc_trans = coord_transform(subways_loc)
14
15 print(subways_loc_trans.head(1))
<ipython-input-103-a13e9199a9d5> in coord_transform(df)
4 for idx, val in enumerate(df['Latitude']):
5 x, y = pyproj.transform(NAD83_LI, NYS_LIZ, df['Longitude'][idx], df['Latitude'][idx])
----> 6 x.set_value(idx, x)
7 y.set_value(idx, y)
8 df['x'] = x
AttributeError: 'float' object has no attribute 'set_value'
Here is the link to my github upload of the file https://github.com/amkaris/SB-Code/blob/master/subways_loc.csv.
Any and all help is appreciated! Thanks!