我有一个程序可以汇集来自不同营销系统的广告统计信息.一切正常,直到我将其转换为.exe格式并运行它.
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 1549, in __call__
return self.func(*args)
File "C:\Users\user\Desktop\alg\TSK_7. Marketing\report_gui.py", line 24, in <lambda>
ok = tk.Button(root, text="DO NOT PRESS", bg="red", command=lambda: self.run())
File "C:\Users\user\Desktop\alg\TSK_7. Marketing\report_gui.py", line 43, in run
report.merge_all()
File "C:\Users\user\Desktop\alg\TSK_7. Marketing\process_data.py", line 400, in merge_all
fb_df = self.fetch_fb()
File "C:\Users\user\Desktop\alg\TSK_7. Marketing\process_data.py", line 156, in fetch_fb
fb_campaigns = from_fb.run_fb(self.start_date, self.end_date) # in JSON format
File "C:\Users\user\Desktop\alg\TSK_7. Marketing\from_fb.py", line 110, in run_fb
return s.get_stats()
File "C:\Users\user\Desktop\alg\TSK_7. Marketing\from_fb.py", line …Run Code Online (Sandbox Code Playgroud) pyinstaller python-requests python-3.5 facebook-marketing-api
我检查了类似问题的其他解决方案,但是sqlite不支持 row_number()和rank()函数,或者没有涉及连接多个表的示例,将它们按多列分组并且同时仅为每个组返回前N个结果.
这是我运行的代码
db = sqlite3.connect('mydb')
cursor = db.cursor()
cursor.execute(
'''
CREATE TABLE orders(
id INTEGER PRIMARY KEY, product_id INTEGER,
client_id INTEGER
)
'''
)
cursor.execute(
'''
CREATE TABLE clients(
id INTEGER PRIMARY KEY, gender TEXT,
city TEXT
)
'''
)
cursor.execute(
'''
CREATE TABLE products(
id INTEGER PRIMARY KEY, category_name TEXT
)
'''
)
orders = [
(9, 6), (3, 10), (8, 6), (4, 8),
(5, 6), (7, 4), (9, 2), (10, 8),
(4, 6), …Run Code Online (Sandbox Code Playgroud) 目标是只保留与某个主题(电影)相关的查询,然后使用 NLP 对这些过滤后的查询进行聚类(词干 -> tf_idf -> pca -> kmeans)。
我尝试使用嵌套循环过滤查询,但需要 10 多个小时才能完成。
filtered = []
with open('search_logs.txt', 'r', encoding='utf-8') as f:
for i, line in enumerate(f):
query, timestamp = line.strip().split('\t')
for word in key_words:
if word in query:
filtered.append(i)
Run Code Online (Sandbox Code Playgroud)
我研究了使用正则表达式 (word1|word2|...|wordN) 的解决方案,但问题是我无法将查询组合成一个大字符串,因为我需要过滤不相关的查询。
更新:日志和关键字的示例
search_logs.txt
'query timestamp\n'
'the dark knight 2019-02-17 19:05:12\n'
'how to do a barrel roll 2019-02-17 19:05:13\n'
'watch movies 2019-02-17 19:05:13\n'
'porn 2019-02-17 19:05:13\n'
'news 2019-02-17 …Run Code Online (Sandbox Code Playgroud) ZeroDivisionError.await asyncio.gather(*tasks, return_exceptions=True)
上面移动await queue.join(),它最终会抛出ZeroDivisionError并停止。1 / 0并运行,它将执行所有内容,但最终会挂起。现在的问题是,我怎样才能同时实现:
.
import asyncio
import random
import time
async def worker(name, queue):
while True:
print('Get a "work item" out of the queue.')
sleep_for = await queue.get()
print('Sleep for the "sleep_for" seconds.')
await asyncio.sleep(sleep_for)
# Error on purpose
1 / 0
print('Notify the queue that the "work item" has been processed.')
queue.task_done()
print(f'{name} has slept for {sleep_for:.2f} seconds')
async …Run Code Online (Sandbox Code Playgroud) 有没有办法从列表中设置 pydantic 模型?我尝试过这个,但它对我不起作用。如果 pydantic 无法做到这一点,如果我仍然需要类型验证和转换、约束等,那么最好的方法是什么?顺序在这里很重要。
from pydantic import BaseModel
from datetime import date
class User(BaseModel):
id: int
name = 'John Doe'
sex: str
money: float = None
dt: date
data = [1, 'Tike Myson', 'male', None, '2022-01-20']
user = User(*data)
>>> TypeError: __init__() takes exactly 1 positional argument (6 given)
Run Code Online (Sandbox Code Playgroud) 我想添加一个列,该列是从每个customer_id的最大日期减去此表的最小日期的结果
输入:
action_date customer_id
2017-08-15 1
2017-08-21 1
2017-08-21 1
2017-09-02 1
2017-08-28 2
2017-09-29 2
2017-10-15 3
2017-10-30 3
2017-12-05 3
Run Code Online (Sandbox Code Playgroud)
得到这张桌子
输出:
action_date customer_id diff
2017-08-15 1 18
2017-08-21 1 18
2017-08-21 1 18
2017-09-02 1 18
2017-08-28 2 32
2017-09-29 2 32
2017-10-15 3 51
2017-10-30 3 51
2017-12-05 3 51
Run Code Online (Sandbox Code Playgroud)
我尝试了这个代码,但它放了很多NaN
group = df.groupby(by='customer_id')
df['diff'] = (group['action_date'].max() - group['action_date'].min()).dt.days
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 asyncio 从数千个 url 中获取一些数据。以下是该设计的简要概述:
Queue一次性填写一堆网址ProducerConsumersConsumer保持异步从请求中提取 urlQueue并发送GET请求问题: asyncio几乎从不显示是否有任何问题,它只是默默地挂起而没有错误。我在print各处放置语句来自己检测问题,但这并没有多大帮助。
根据输入网址的数量和消费者的数量或限制,我可能会收到以下错误:
Task was destroyed but it is pending!task exception was never retrieved future: <Task finished coro=<consumer()aiohttp.client_exceptions.ServerDisconnectedErroraiohttp.client_exceptions.ClientOSError: [WinError 10053] An established connection was aborted by the software in your host machine问题:如何检测和处理中的异常asyncio?如何在不中断的情况下重试Queue?
Bellow 是我在查看异步代码的各种示例时编译的代码。目前,def get_video_title函数末尾存在故意错误。运行时,什么都不显示。
import asyncio
import aiohttp
import json
import re
import nest_asyncio
nest_asyncio.apply() …Run Code Online (Sandbox Code Playgroud) 我在熊猫数据框中有 20 万行带有消息的行。每条消息平均包含 230 个字符,上面点缀着像这样的表情符号。
现在我想过滤掉除上下英文和俄文字母以及这些符号之外的所有内容: #@/:%.,_-
这样做的最有效方法是什么?
我有以下SQL表
user_id product_1 product_2 product_3
123 Scissors Stone Paper
Run Code Online (Sandbox Code Playgroud)
我编写了此代码以将结果格式化为JSON,但无法以所需的格式获取它。如果我将所有产品列都命名为namesql则返回错误
Use different names and aliases for each column in SELECT list.
SQL代码:
select
product1 as 'Product1',
product2 as 'Product2',
product3 as 'Product3'
from Recommendations
where user_id = '123'
FOR JSON PATH, ROOT('Offers')
Run Code Online (Sandbox Code Playgroud)
电流输出:
{"offers":[
{"Product1": "Scissors", "Product2": "Stone", "Product3": "Paper"}
]
}
Run Code Online (Sandbox Code Playgroud)
所需的输出:
{"offers":[
{"name": "Scissors"},
{"name": "Stone"},
{"name": "Paper"}
]
}
Run Code Online (Sandbox Code Playgroud)