PyCharmとPython 3.5が動作しています。 私はCSVソースから(ソース、宛先)を取得しようとしており、時間、距離の列に対する応答を保存しています。私はそのままこのコードを実行する場合 はhttp://www.analyticsvidhya.com/blog/2015/03/hacking-google-maps-create-distance-features-model-applications/Python - pandas、チェーンインデックスエラー
しかし、それは動作しません:
私はこのコードを複製しようとしています。連鎖インデックスが原因でコードが実行されなくなったと思います... 必要に応じてcsvをアップロードできます。あなたの助けのための
おかげ
エラーライン:
cities['distance'][i] = finddist(source, destination)
cities['time'][i] = findtime(source, destination)
コード:
from googlemaps import Client
from datetime import datetime
def finddist(source, destination):
gmaps = Client(key='mykey')
now = datetime.now()
directions_result = gmaps.directions(source, destination, mode="driving", departure_time=now)
for map1 in directions_result:
overall_stats = map1['legs']
for dimensions in overall_stats:
distance = dimensions['distance']
return [distance['text']]
def findtime(source, destination):
gmaps = Client(key='mykey')
now = datetime.now()
directions_result = gmaps.directions(source, destination, mode="driving", departure_time=now)
for map1 in directions_result:
overall_stats = map1['legs']
for dimensions in overall_stats:
duration = dimensions['duration']
return [duration['text']]
import numpy as np
import pandas as pd
import pylab as pl
import os
os.chdir("https://stackoverflow.com/users/merterten/documents")
cities = pd.read_csv("cities.csv")
cities["distance"] = 0
cities["time"] = 0
for i in range(0, 8):
source = cities['Source'][i]
destination = cities['Destination'][i]
cities['distance'][i] = finddist(source, destination)
cities['time'][i] = findtime(source, destination)
エラー:
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 /Users/merterten/PycharmProjects/untitled/maps/__init__.py
/Users/merterten/PycharmProjects/untitled/maps/__init__.py:37: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
cities['distance'][i] = finddist(source, destination)
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/core/indexing.py:132: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
self._setitem_with_indexer(indexer, value)
/Users/merterten/PycharmProjects/untitled/maps/__init__.py:38: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
cities['time'][i] = findtime(source, destination)
Process finished with exit code 0
ありがとうございました。 – Hush
http://resim.patifile.com/2016/05/25/ScreenShot2016-05-25at20.43.00b7ac3.png – Hush