For geocoding with ArcGIS, credentials have to be provided gis = GIS("http://www.arcgis.com", "username", "password")
.
In terms of pandas, this code should do the work (adapted from @Marcelo Villa's answer)
from arcgis.geocoding import reverse_geocode
from arcgis.geometry import Geometry
from arcgis.gis import GIS
import pandas as pd
gis = GIS("http://www.arcgis.com", "***", "***")
def get_zip(df, lon_field, lat_field):
location = reverse_geocode((Geometry({"x":float(df[lon_field]), "y":float(df[lat_field]), "spatialReference":{"wkid": 4326}})))
return location['address']['Postal']
df = pd.DataFrame({
'Lat': [29.39291, 29.39923, 29.40147, 29.38752, 29.39291, 29.39537, 29.39343, 29.39291, 29.39556],
'Lon': [-98.50925, -98.51256, -98.51123, -98.52372, -98.50925, -98.50402, -98.49707, -98.50925, -98.53148]
})
zipcodes = df.apply(get_zip, axis=1, lat_field='Lat', lon_field='Lon')

Probably not as smart as pandas but using Python's internal module csv and ArcGIS's API for Python Reverse Geocoding.
from arcgis.geocoding import reverse_geocode
from arcgis.geometry import Geometry
from arcgis.gis import GIS
import csv
gis = GIS("http://www.arcgis.com", "***", "***")
coords = [
(29.39291, -98.50925),
(29.39923, -98.51256),
(29.40147, -98.51123),
(29.38752, -98.52372),
(29.39291, -98.50925),
(29.39537, -98.50402),
(29.39343, -98.49707),
(29.39291, -98.50925),
(29.39556, -98.53148)
]
result = []
for lat, lon in coords:
pt = Geometry({
"x": float(lon),
"y": float(lat),
"spatialReference": {
"wkid": 4326
}
})
try:
result.append({'lat': lat, 'lon': lon, 'geocoded': reverse_geocode(pt)})
except:
pass
result_zip = []
for item in result:
result_item = {
'lat': item['lat'],
'lon': item['lon'],
'zip': item['geocoded']['address']['Postal']
}
result_zip.append(result_item)
keys = result_zip[0].keys()
with open('output.csv', 'w', encoding='utf8', newline='') as output_file:
dict_writer = csv.DictWriter(output_file, keys, delimiter=';', quoting=csv.QUOTE_NONE, lineterminator='\r')
dict_writer.writeheader()
dict_writer.writerows(result_zip)
Output csv-file looks as following
