I have a Pandas DataFrame containing train stations latitudes and longitudes, called stops
:
station_id,station_name,station_lat,station_lon
'101','Van Cortlandt Park - 242 St',40.889248,-73.898583
'103','238 St',40.884667,-73.90087
'104','231 St',40.878856,-73.904834
'106','Marble Hill - 225 St',40.874561,-73.909831
Using pd.iterrows()
, I coupled the latitudes and longitudes into tuples, packed them into a list, converted the list into a Pandas Series, and added the Series to the DataDrame as a new column, like so:
latlon_list = []
for ind, row in stops.iterrows():
latlon_list.append((stops.at[ind, 'station_lat'], stops.at[ind, 'station_lon']))
latlon_series = pd.Series(latlon_list)
stops.insert(loc=4, column='station_lat_lon', value=latlon_series)
This mutated some of the lat lon values and added a few decimal places to them:
station_id station_name station_lat station_lon station_lat_lon
0 101 Van Cortlandt Park - 242 St 40.889248 -73.898583 (40.889247999999995, -73.898583)
1 103 238 St 40.884667 -73.900870 (40.884667, -73.90087)
2 104 231 St 40.878856 -73.904834 (40.878856, -73.904834)
3 106 Marble Hill - 225 St 40.874561 -73.909831 (40.874561, -73.90983100000001)
4 107 215 St 40.869444 -73.915279 (40.869444, -73.915279)
The mutation occurred in row 0 and row 3, but not the other rows. On row 0, the latitude figure is mutated, but on row 3, the longitude figure is mutated. Why does this happen, and how can I prevent it from happening?