我正在尝试通过 Workbench 将架构从我的个人计算机传输到 RDS。我已导出 SQL 转储文件并尝试将其导入 RDS。但是,我收到以下错误:
Unhandled exception: local variable 'pwd' referenced before assignment
Check the log for more details.
Run Code Online (Sandbox Code Playgroud)
日志文件有这样的内容:
14:05:01 [WRN][wb_admin_export.py:process_db:277]: Task exited with code 1
14:05:01 [ERR][ pymforms]: Unhandled exception in Python code:
Traceback (most recent call last):
File "C:\Program Files\MySQL\MySQL Workbench 8.0 CE\modules\wb_admin_export.py", line 1334, in _update_progress
r = self.update_progress()
File "C:\Program Files\MySQL\MySQL Workbench 8.0 CE\modules\wb_admin_export.py", line 913, in update_progress
self.start()
File "C:\Program Files\MySQL\MySQL Workbench 8.0 CE\modules\wb_admin_export.py", line 1323, in start
password = self.get_mysql_password(self.bad_password_detected)
File …Run Code Online (Sandbox Code Playgroud) 我正在尝试根据包含与几个别名表的联接的查询删除记录。
以下是有问题的表格:
class Match(Base):
id_ = Column(Integer, primary_key=True)
tournament_id = Column(Integer, ForeignKey("myschema.tournament.id_"))
round_id = Column(TINYINT, index=True)
player_id_p1 = Column(Integer, ForeignKey("myschema.player.id_"))
player_id_p2 = Column(Integer, ForeignKey("myschema.player.id_"))
p1 = relationship("Player", foreign_keys=[player_id_p1])
p2 = relationship("Player", foreign_keys=[player_id_p2])
class Tournament(Base):
id_ = Column(Integer, primary_key=True)
original_id = Column(Integer, index=True)
tour_id = Column(TINYINT, index=True)
match = relationship("Match", backref="tournament")
class Player(Base):
id_ = Column(Integer, primary_key=True)
original_id = Column(Integer, index=True)
tour_id = Column(TINYINT, index=True)
match = relationship(
'Match',
primaryjoin=("or_(Player.id_ == Match.player_id_p1, Player.id_ == Match.player_id_p2)"),
overlaps="p1, p2",
)
Run Code Online (Sandbox Code Playgroud)
值得一提的是,这些表格是从第三方数据库填充的,该数据库包含来自两个网球巡回赛的锦标赛、球员和比赛;ATP 和 WTA。在该数据库中,每个巡回赛都有单独的锦标赛、球员和比赛表。我已将它们导入数据库中的组合表中,并使用一个 …
给定以下数据框:
+------------+--------+
| Date | Amount |
+------------+--------+
| 01/05/2019 | 15 |
| 27/05/2019 | 20 |
| 27/05/2019 | 15 |
| 25/06/2019 | 10 |
| 29/06/2019 | 25 |
| 01/07/2019 | 50 |
+------------+--------+
Run Code Online (Sandbox Code Playgroud)
我需要获取所有先前日期的滚动总和,如下所示:
+------------+--------+
| Date | Amount |
+------------+--------+
| 01/05/2019 | NaN |
| 27/05/2019 | 15 |
| 27/05/2019 | 15 |
| 15/06/2019 | 35 |
| 29/06/2019 | 10 |
| 01/07/2019 | 35 |
+------------+--------+ …Run Code Online (Sandbox Code Playgroud) 我正在使用 pandas DataFrames,我想知道引用列名称的约定是什么。我应该将列名称定义为单元格顶部的字符串变量吗?这样,如果我决定更改列名,我只需要更改变量分配?
在这里查看了 PEP 8 ,但没有看到任何指导。
我有以下简化的数据库访问层和两个表:
class DataAccessLayer():
def __init__(self):
conn_string = "mysql+mysqlconnector://root:root@localhost/"
self.engine = create_engine(conn_string)
Base.metadata.create_all(self.engine)
Session = sessionmaker()
Session.configure(bind=self.engine)
self.session = Session()
class MatchesATP(Base):
__tablename__ = "matches_atp"
__table_args__ = {"schema": "belgarath", "extend_existing": True}
ID_M = Column(Integer, primary_key=True)
ID_T_M = Column(Integer, ForeignKey("oncourt.tours_atp.ID_T"))
class TournamentsATP(Base):
__tablename__ = "tours_atp"
__table_args__ = {"schema": "oncourt", "extend_existing": True}
ID_T = Column(Integer, primary_key=True)
NAME_T = Column(String(255))
Run Code Online (Sandbox Code Playgroud)
我希望能够将两个表的架构名称切换到测试数据库,如下所示:
belgarath 到 belgarath_test
oncourt 到 oncourt_test
我试过添加:
self.session.connection(execution_options={"schema_translate_map": {"belgarath": belgarath, "oncourt": oncourt}})
Run Code Online (Sandbox Code Playgroud)
到底部DataAccessLayer然后用两个变量初始化类,如下所示:
def __init__(self, belgarath, oncourt):
Run Code Online (Sandbox Code Playgroud)
但是,当我构建以下查询时:
dal = DataAccessLayer("belgarath_test", …Run Code Online (Sandbox Code Playgroud) 当我尝试运行调试器时:
C:\Users\Philip\OneDrive\Betting\Capra\Tennis\polgara> cmd /C "C:/Users/Philip/miniconda3/envs/capra/python.exe c:\Users\Philip\.vscode\extensions\ms-python.python-2020.8.101144\pythonFiles\lib\python\debugpy\launcher 53607 -- c:\Users\Philip\OneDrive\Betting\Capra\Tennis\polgara\updater.py "
C:\Users\Philip\miniconda3\envs\capra\lib\site-packages\numpy\__init__.py:138: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
from . import _distributor_init
Run Code Online (Sandbox Code Playgroud)
我已经发现,如果我安装numpy到我的base环境中,就可以解决该错误。问题是如何激活capra调试器的环境?
我尝试遵循VS Code 的指导:
1. pythonPath property of the selected debug configuration in launch.json
Run Code Online (Sandbox Code Playgroud)
我的launch.json文件:
{
// Use …Run Code Online (Sandbox Code Playgroud) 运行此代码时出现错误:
engine = sa.create_engine([connection_str])
connection = engine.connect()
Run Code Online (Sandbox Code Playgroud)
部分回溯:
Exception during reset or similar
Traceback (most recent call last):
File "/Users/philipjoss/opt/miniconda3/envs/capra/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 682, in _finalize_fairy
fairy._reset(pool)
File "/Users/philipjoss/opt/miniconda3/envs/capra/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 887, in _reset
pool._dialect.do_rollback(self)
File "/Users/philipjoss/opt/miniconda3/envs/capra/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 667, in do_rollback
dbapi_connection.rollback()
File "/Users/philipjoss/opt/miniconda3/envs/capra/lib/python3.9/site-packages/mysql/connector/connection.py", line 1236, in rollback
self._execute_query("ROLLBACK")
File "/Users/philipjoss/opt/miniconda3/envs/capra/lib/python3.9/site-packages/mysql/connector/connection.py", line 1248, in _execute_query
self.cmd_query(query)
File "/Users/philipjoss/opt/miniconda3/envs/capra/lib/python3.9/site-packages/mysql/connector/connection.py", line 828, in cmd_query
packet.extend(lc_int(len(self._query_attrs)))
File "/Users/philipjoss/opt/miniconda3/envs/capra/lib/python3.9/site-packages/mysql/connector/utils.py", line 164, in lc_int
return bytearray(struct.pack('<B', i))
AttributeError: 'NoneType' object has no attribute 'pack'
Exception closing connection <mysql.connector.connection.MySQLConnection …Run Code Online (Sandbox Code Playgroud) 我正在尝试将以下 SQL 转换为 SQLAlchemy:
select t1.id, t1.field_A,
max(case when t2.field_B = 1 then t2.field_C end) test_2_field_b_1,
max(case when t2.field_B = 2 then t2.field_C end) test_2_field_b_2
from test_1 t1
inner join test_2 t2 on t2.field_A = t1.field_A
group by t1.id, t1.field_A
Run Code Online (Sandbox Code Playgroud)
我已经做到了:
qry = session.query(
Test1.id_,
Test2.field_A,
func.max(case((Test2.field_B.__eq__(1), "Test2.field_C"))).label("test_2_field_b_1"),
func.max(case((Test2.field_B.__eq__(2), "Test2.field_C"))).label("test_2_field_b_2"),
)
qry = qry.select_from(Test1)
qry = qry.join(Test2, Test2.field_A.__eq__(Test1.field_A))
qry = qry.group_by(Test1.id_, Test2.field_A)
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
NotImplementedError: Operator 'getitem' is not supported on this expression
Run Code Online (Sandbox Code Playgroud)
在线上:
func.max(case((Test2.field_B.__eq__(1), "Test2.field_C"))).label("test_2_field_b_1"),
Run Code Online (Sandbox Code Playgroud)
所以不会让我发布整个回溯,因为它说代码太多了!
我哪里出错了?
给定以下数据框:
+------+-----+-----+
| Year | Cat | Bin |
+------+-----+-----+
| 2000 | A | 0 |
| 2000 | A | 1 |
| 2001 | A | 0 |
| 2001 | B | 1 |
| 2001 | B | 0 |
| 2001 | B | 1 |
+------+-----+-----+
d = {
'year': [2000, 2000, 2001, 2001, 2001, 2001],
'cat': ["A", "A", "A", "B", "B", "B", ],
'bin': [0, 1, 0, 1, 0, 1],
}
df …Run Code Online (Sandbox Code Playgroud) 给定以下数据框:
| A | 乙 | C | d | e | 标准差 |
|---|---|---|---|---|---|
| -100 | 2 | 3 | 60 | 4 | 1 |
| 7 | 5 | -50 | 9 | 130 | 2 |
如何计算sd排除每行的最小值和最大值的标准差列?
实际的数据帧有几百万行长,所以矢量化的东西会很棒!
复制:
df = pd.DataFrame(
{"a": [-100, 7], "b": [2, 5], "c": [3, -50], "d": [60, 9], "e": [4, 130]}
)
Run Code Online (Sandbox Code Playgroud) 鉴于以下简单表:
+-----+-------------+---------+----+
| id_ | match_op_id | version | p1 |
+-----+-------------+---------+----+
| 1 | 1 | 1 | 1 |
| 2 | 1 | 1 | 5 |
| 3 | 1 | 2 | 3 |
| 4 | 1 | 2 | 4 |
| 5 | 2 | 1 | 1 |
| 6 | 2 | 1 | 5 |
| 7 | 2 | 2 | 3 |
| 8 | 2 | …Run Code Online (Sandbox Code Playgroud)