【问题标题】:How to get only the value back from Postgres without the table name and id?如何只从 Postgres 中获取没有表名和 id 的值?
【发布时间】:2022-08-07 01:33:19
【问题描述】:

下面的行将值与 \'table name\' 一起放入 \'dataFrame\' 所以当我尝试使用它时,我得到错误: InvalidSchema: No connection adapters were found for \'club_url\\n0 .. . 感谢您的关注。

dataFrame = pds.read_sql(\"SELECT club_url FROM premier_league WHERE club_name LIKE \'%%Chel%%\'\", dbConnection)

错误消息的完整列表: 回溯(最近一次通话最后): 文件

\"C:\\Users\\zszen\\PycharmProjects\\venv\\Football\\Scripts\\import_players_csv.py\", line 23, in <module>
    r = s.get(url)
  File \"C:\\Users\\zszen\\PycharmProjects\\venv\\Football\\lib\\site-packages\\requests\\sessions.py\", line 600, in get
    return self.request(\"GET\", url, **kwargs)
  File \"C:\\Users\\zszen\\PycharmProjects\\venv\\Football\\lib\\site-packages\\requests\\sessions.py\", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File \"C:\\Users\\zszen\\PycharmProjects\\venv\\Football\\lib\\site-packages\\requests\\sessions.py\", line 695, in send
    adapter = self.get_adapter(url=request.url)
  File \"C:\\Users\\zszen\\PycharmProjects\\venv\\Football\\lib\\site-packages\\requests\\sessions.py\", line 792, in get_adapter
    raise InvalidSchema(f\"No connection adapters were found for {url!r}\")
requests.exceptions.InvalidSchema: No connection adapters were found for \'club_url\\n0  https://www.transfermarkt.co.uk/fc-chelsea/sta...\'
                                            club_url
0  https://www.transfermarkt.co.uk/fc-chelsea/sta...
  • 定义/显示“尝试使用它”。还显示完整的错误消息。添加为问题的更新。
  • 回溯与read_sql 完全无关。请提供minimal reproducible example
  • 产生错误的代码是什么?
  • - 创建错误的代码是提供的行 dataFrame = pds.read_sql(\"SELECT club_url FROM Premier_league WHERE club_name LIKE \'%%Chel%%\'\", dbConnection)。我想要一种方法来显示值,而不是像你在底部看到的那样> 表名:返回 club_url,并且返回值的位置 \'0\'。值本身就是 \'url\'。
  • Traceback 显示请求有问题,但它有问题,因为我给请求提供了错误的 url。数据库存储我想要使用的值,但 read_sql 的工作方式还加载了 <table name> 和位置。如果它只返回我的有效 url,就不会有错误。回溯与 read_sql 无关,但我的问题是。我无法提供示例,因为您没有我的数据库。这有帮助吗: from requests_html import HTMLSession s = HTMLSession() url = dataFrame r = s.get(url) print(r)

标签: python sql postgresql sqlalchemy


【解决方案1】:

只需在行尾使用“.values”即可将值或值作为列表获取。

【讨论】:

    猜你喜欢
    • 2022-11-02
    • 1970-01-01
    • 2020-02-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多