熊猫返回Traceback,我不知道为什么

时间:2017-11-01 18:31:02

标签: python pandas

我通过pip安装了pandas,我相信我拥有所有它的依赖项。当我尝试运行它时,我一遍又一遍地得到同样的错误。 Panda Trace 我不知道为什么我一直收到这个错误。我看了,一切似乎都没问题。

这是我的代码:

import requests
from bs4 import BeautifulSoup
import pandas as pd
page = requests.get("http://forecast.weather.gov/MapClick.php?lat=37.7772&lon=-122.4168")
soup = BeautifulSoup(page.content, 'html.parser')
seven_day = soup.find(id="seven-day-forecast")
forecast_items = seven_day.find_all(class_="tombstone-container")
tonight = forecast_items[0]
period = tonight.find(class_="period-name").get_text()
short_desc = tonight.find(class_="short-desc").get_text()
temp = tonight.find(class_="temp").get_text()
img = tonight.find("img")
desc = img['title']
period_tags = seven_day.select(".tombstone-container .period-name")
periods = [pt.get_text() for pt in period_tags]
short_descs = [sd.get_text() for sd in seven_day.select(".tombstone-container .short-desc")]
temps = [t.get_text() for t in seven_day.select(".tombstone-container .temp")]
descs = [d["title"] for d in seven_day.select(".tombstone-container img")]
weather = pd.DataFrame({
    "period": periods,
    "short_desc": short_descs,
    "temp": temps,
    "desc": descs
})
print (weather)

有关如何修复它的任何想法?

1 个答案:

答案 0 :(得分:0)

看起来pytz的依赖是错误的版本。

pip install pytz --upgrade

如果它没有帮助,请卸载pytz并再次安装pandas:

pip uninstall pytz pandas
pip install pandas

我无法重现此错误。你能告诉Python,pandas和pytz版本吗?