Python - pandas, chain indexing error
<p>I have PyCharm and Python 3.5 running.
I am try to get (source, destination) from the csv source, and store responses to time, distance columns.</p>

<p>I am trying to replicate this code:
<a href="http://www.analyticsvidhya.com/blog/2015/03/hacking-google-maps-create-distance-features-model-applications/" rel="nofollow">http://www.analyticsvidhya.com/blog/2015/03/hacking-google-maps-create-distance-features-model-applications/</a></p>

<p>However if I run this code as is, it doesn't work.</p>

<p>Code stops running because of chain indexing I think...
I can upload csv if desired.</p>

<p>Thanks for your help</p>

<p><a href="http://i.stack.imgur.com/PGnCv.png" rel="nofollow">INPUT: cities.csv</a></p>

<p>error lines:</p>

<pre><code>cities['distance'][i] = finddist(source, destination)
cities['time'][i] = findtime(source, destination)
</code></pre>

<p>Code:</p>

<pre><code>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("/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)
</code></pre>

<p>Error:</p>

<pre><code>/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
</code></pre>