2 回答

TA貢獻1757條經驗 獲得超7個贊
如果我理解正確,您可以矢量化此操作并使用坐標的字符串表示形式:
import pandas as pd
# Make pandas print entire strings without truncating them
pd.set_option("display.max_colwidth", -1)
# Create dummy-df from your example
df = pd.DataFrame({"start_latitude": [40.76, 123.00], "start_longitude": [-73.98, 456.00], "end_latitude": [40.65, 789.00], "end_longitude": [-73.98, 0.00]})
print df
# Set globals
mode = "walking"
API_KEY = "my_key"
# Create the url strings for each row
df["distance_matrix_url"] = "origins=" + df["start_latitude"].map(str) + "," + df["start_longitude"].map(str) + "&destinations=" + df["end_latitude"].map(str) + "," + df["end_longitude"].map(str) + "&mode=" + mode + "&languge=en-EN&key=" + API_KEY
# Print results
print df
輸出:
end_latitude end_longitude start_latitude start_longitude distance_matrix_url
0 40.65 -73.98 40.76 -73.98 origins=40.76,-73.98&destinations=40.65,-73.98&mode=walking&languge=en-EN&key=my_key
1 789.00 0.00 123.00 456.00 origins=123.0,456.0&destinations=789.0,0.0&mode=walking&languge=en-EN&key=my_key
這是你要找的嗎?
添加回答
舉報