【发布时间】:2021-08-22 00:52:10
【问题描述】:
我需要从导入的模块中提取 5000 个结果,但如果我尝试返回 1000,我会收到错误消息。我最多可以返回 500 个结果 (num_players=500)。理想情况下,我可以抽取 5000 个随机结果,但我猜前 5000 个必须这样做。我只需要样本数据就可以在 Excel 中运行分析。以下代码是从此处找到的文档中的示例中提取的。 https://pyett.readthedocs.io/en/latest/cohort.html
有人对我如何使其正确运行有任何建议吗?为什么会失去与数据库的连接?
from pyETT import ett
import pandas as pd
lb_cohort = ett.Cohort(ett.ETT().get_leaderboard(num_players=1000))
lb_cohort.size
df = lb_cohort.players_dataframe()
print(df)
file_name = 'export_file.xlsx'
df.to_excel(file_name)
print('DataFrame is written to Excel File successfully.')
这是我得到的例外:
Message=无法连接到主机www.elevenvr.club:443ssl:default [信号量超时期限已过]
来源=C:\Users\Apache Paint\source\repos\Patrick_Kimble \Patrick_Kimble.py
堆栈跟踪:
文件“C:\Users\Apache Paint\source\repos\Patrick_Kimble\Patrick_Kimble.py”,第 7 行,在(当前帧)
lb_cohort = ett.Cohort(ett.ETT().get_leaderboard(num_players=1000))
HTTPSConnectionPool(host='www.elevenvr.club', port=443): url: /accounts/search/bensnow/ 超过最大重试次数(由 NewConnectionError(': Failed to建立新连接:[WinError 10060]
连接尝试失败,因为连接方在一段时间后没有正确响应,或者连接失败,因为连接的主机没有响应'))
编辑:
我创建了一个循环来尝试从数据库中提取所有数据。
for i in range(1, 500000):
try:
if int(i) % 100 == 0:
print('Loop is at:', i)
user_id = i
line = ett.ett_parser.get_user(user_id)
temp_df = pd.DataFrame(line, index=[i])
self.df_master = self.df_master.append(temp_df, ignore_index = True)
except Exception:
print("Error:",i )
MDR 的答案可以返回随机数据。但我需要使用describe() 函数来拉回更多其他细节,但它只接受“队列”类型。
例子:
import pandas as pd
lb_cohort = ett.Cohort(ett.ETT().get_leaderboard(num_players=10))
lb_cohort.size
lb_cohort.describe()
应该返回类似于下图的内容。
【问题讨论】:
-
网站可能故意限制大型请求以限制带宽使用。
-
没有解决办法吗?
-
在下面查看我的答案。在搜索随机用户名时,我设法从循环中获取了 11,541 个唯一用户名行。如果您喜欢它,请给它投票并标记为答案:o)。
标签: python sql pandas dataframe python-import