我使用的是python3.6。下面的代码是使用json模块来解析数据:
import urllib.request
from pandas import *
from pandas import json
import numpy as np
import pandas as pd
import requests
import urllib
import time
def request_image_info(lat, lon):
res = urllib.request.urlopen('https://biocache.ala.org.au/ws/explore/group/Plants.json?lat='+str(lat)+'&lon='+str(lon)+'&pageSize=1&radius=1')
json_data = json.load(res)
guid = json_data[0]['guid']
name = json_data[0]['name']
family = json_data[0]['family']
common_name = json_data[0]['commonName']
count = json_data[0]['count']
rank = json_data[0]['rank']
kingdom = json_data[0]['kingdom']
image_id = time.time()
运行此代码时出现以下错误。第19行是代码json_data = json.load(res)
Traceback (most recent call last):
File "loadImages.py", line 57, in <module>
request_image_info(row[2], row[3])
File "loadImages.py", line 19, in request_image_info
json_data = json.load(res)
File "/Users/admin/tmp/p36/lib/python3.6/site-packages/pandas/util/_depr_module.py", line 61, in __getattr__
obj = getattr(deprmodule, name)
AttributeError: module 'pandas.json' has no attribute 'load'
我已经安装了pandas模块,如下所示:
$ pip3 install pandas
Requirement already satisfied: pandas in /usr/local/lib/python3.6/site-packages
Requirement already satisfied: numpy>=1.7.0 in /usr/local/lib/python3.6/site-packages (from pandas)
Requirement already satisfied: pytz>=2011k in /usr/local/lib/python3.6/site-packages (from pandas)
Requirement already satisfied: python-dateutil>=2 in /usr/local/lib/python3.6/site-packages (from pandas)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.6/site-packages (from python-dateutil>=2->pandas)
我该如何解决这个问题?
以下是我正在使用的python和pip版本:
$ python --version
Python 3.6.2
$ pip --version
pip 9.0.1 from /Users/admin/tmp/p36/lib/python3.6/site-packages (python 3.6)
答案 0 :(得分:0)
您输入了错误的json
。删除
from pandas import json
并做
import json
代替。