I had a problem with replacing the original values of the address column with the address I get from Places API response. Even though the code and its responses were smooth-sailing, something must have gone awry with the data.loc[i,add_col]=address
since the dataset remains the same after applying this function
import googlemapsimport win32com.client as win32API_KEY = "(MY API KEY)"map_client = googlemaps.Client(API_KEY)def replace_address(data,add_col): if data[add_col].notna().any(): data = data[data[add_col].notna()] for i in data.index: location_name = data.loc[i,add_col] response = map_client.places(query=location_name) if response['status'] == 'OK': places = response['results'] place=places[0] name = place['name'] address = place.get('formatted_address', 'Address not available') print(f"id: {i}, Query:{location_name}, Name: {name}, Address: {address}") data.loc[i,add_col]=address else: print("No places found or error occurred:", response['status']) else: passdf_replace_add = data[data[["Huyện","Quận"]].isnull().sum(axis=1)==1]replace_address(df_replace_add,"Địa chỉ")
df_replace_add still remains the same even when I change .loc() to .iloc() with the corresponding indexer. I have been struggling with this for hours yet not figuring out how to solve it. Any assistance is much appreciated T.T
Updated: I also received a warning. Does this have anything to do with the problem:
SettingWithCopyWarning:A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copydata.loc[i,add_col]=address