Hello everyone! I am seeking your help on the following task.
So, thankfully to you I was able to extract geo coordinates from a tweet, and save latitude/longitude as float64 in separate columns. Now, I need to convert coordinates to FIPS codes. The easiest way seems to be using -stateplane-:
So, thankfully to you I was able to extract geo coordinates from a tweet, and save latitude/longitude as float64 in separate columns. Now, I need to convert coordinates to FIPS codes. The easiest way seems to be using -stateplane-:
import stateplane stateplane.identify(-78.873165, 39.207769, fmt='fips') # lon first '4701'To create a new column with identifed FIPS code, I do the following:
for index, row in df.iterrow(): df["FIPS"] = df[stateplane.identify('lon', 'lat', fmt='fips')]But I guess I am doing it incorrectly -- i.e., specifying lon/lat columns to get values from, as I get the following error:
Error:---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/Users/mymac/anaconda/lib/python3.6/site-packages/shapely/geometry/point.py in geos_point_from_py(ob, update_geom, update_ndim)
201 # From array protocol
--> 202 array = ob.__array_interface__
203 assert len(array['shape']) == 1
AttributeError: 'tuple' object has no attribute '__array_interface__'
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
<ipython-input-20-e8453e36b340> in <module>()
1 for index, row in test.iterrows():
----> 2 text["FIPS"] = stateplane.identify('lon', 'lat', fmt='fips') # lon then lat
/Users/mymac/anaconda/lib/python3.6/site-packages/stateplane/stateplane.py in identify(lon, lat, fmt, statefp, countyfp)
83 '''
84
---> 85 result = _id(lon, lat, statefp=statefp, countyfp=countyfp)
86
87 try:
/Users/mymac/anaconda/lib/python3.6/site-packages/stateplane/stateplane.py in _id(lon, lat, statefp, countyfp)
63 raise ValueError("SPCS not found for statefp={}".format(statefp))
64
---> 65 target = Point(lon, lat)
66 result = None
67
/Users/mymac/anaconda/lib/python3.6/site-packages/shapely/geometry/point.py in __init__(self, *args)
47 BaseGeometry.__init__(self)
48 if len(args) > 0:
---> 49 self._set_coords(*args)
50
51 # Coordinate getters and setters
/Users/mymac/anaconda/lib/python3.6/site-packages/shapely/geometry/point.py in _set_coords(self, *args)
127 self._geom, self._ndim = geos_point_from_py(args[0])
128 else:
--> 129 self._geom, self._ndim = geos_point_from_py(tuple(args))
130
131 coords = property(BaseGeometry._get_coords, _set_coords)
/Users/mymac/anaconda/lib/python3.6/site-packages/shapely/geometry/point.py in geos_point_from_py(ob, update_geom, update_ndim)
233 coords = ob
234 n = len(coords)
--> 235 dx = c_double(coords[0])
236 dy = c_double(coords[1])
237 dz = None
TypeError: must be real number, not str
Please advise how to do it right.