我是使用pandas的新手,我试图修复我的脚本的最后一部分。当调用以下函数时,我得到错误:
ValueError: Cannot set a DataFrame with multiple columns to the single column place_name
def get_place_name(latitude, longitude):
location = geolocator.reverse(f"{latitude}, {longitude}", exactly_one=True)
if location is None:
return None
else:
return location.address
此函数从此处调用:
metadata_df = extract_metadata(dir_path)
print("[+] Metadata extracted from all image files")
print(metadata_df.columns)
geolocator = Nominatim(user_agent="exif_location")
metadata_df['place_name'] = metadata_df.apply(
lambda row: get_place_name(
row['gps_latitude'], row['gps_longitude']),
axis=1)
任何帮助或建议将不胜感激:)
1条答案
按热度按时间w6mmgewl1#
你的代码对我来说很好用(Pandas1.5.3,Geopy 2.3.0):
输出
我不明白为什么你的函数试图返回一个有多列的 Dataframe 。如果你这样做,你的错误是可重复的: