Skip to content
The Chat Archive

Side-by-side comparison

Both conversations start with the same prompt. Responses were generated in different, uncontrolled contexts. This is not a benchmark.
First prompt

我需要上海各地铁站的经纬度,以dataframe形式返回,并保存到本地

gpt-3.5-turbo-0301· OpenAI WildChat-4.8M (AI2)

您好,以下是获取上海地铁站经纬度的代码,并将其保存为dataframe形式:

import requests
import pandas as pd

url = 'https://restapi.amap.com/v3/place/text'

data = {
    'keywords': '上海地铁站',
    'city': '上海',
    'output': 'json',
    'key': '您的高德API密钥',
    'offset': 20
}

res = requests.get(url, params=data)
result = res.json()

df = pd.DataFrame(columns=['name', 'lng', 'lat'])

for poi in result['pois']:
    name = poi['name']
    location = poi['location'].split(',')
    lng = float(location[0])
    lat = float(location[1])
    
    df = df.append({
        'name': name,
        'lng': lng,
        'lat': lat
    }, ignore_index=True)

df.to_csv('上海地铁站经纬度.csv', index=False)
print('保存成功!')

需要将上述代码中的'您的高德API密钥'替换为您自己的高德API密钥。此外,您也可以根据需要调整查询结果的数量,只需修改data中的'offset'参数即可。

代码执行完成后,会在当前工作目录下生成一个名为'上海地铁站经纬度.csv'的文件,保存了所有上海地铁站的经纬度信息。

gpt-3.5-turbo-0301· OpenAI WildChat-4.8M (AI2)

以下是获取上海各地铁站经纬度的代码,需要使用 requests 和 pandas 库:

import requests
import pandas as pd

url = 'https://shanghaicity.openservice.kankanews.com/public/bus/metroStationInfo.json'

response = requests.get(url).json()

stations = response['data']

data = []

for station in stations:
    name = station['name']
    lon = float(station['longitude'])
    lat = float(station['latitude'])
    data.append([name, lon, lat])

df = pd.DataFrame(data, columns=['name', 'longitude', 'latitude'])

df.to_csv('shanghai_metro_stations.csv', index=False)

上述代码将对上海所有地铁站的经纬度数据获取后保存为 CSV 文件。

Sign in to record which response you prefer.