大佬们,帮忙看看,这个代码报木马。是用GPT写的,是怎么回事,可以优化吗[Python] 纯文本查看 复制代码 import sqlalchemy as sa
import pandas as pd
# 创建 SQLAlchemy 连接字符串
conn_str = '屏蔽屏蔽屏蔽屏蔽'
# 使用 SQLAlchemy 连接
engine = sa.create_engine(conn_str)
# 执行查询
query = """
SELECT SUBJECT
FROM [dbo].[CTP_AFFAIR]
WHERE [MEMBER_ID] = N'7317073679666597063'
AND ([SUBJECT] LIKE N'%费用%' OR [SUBJECT] LIKE N'%差旅%')
AND [SUBJECT] NOT LIKE N'%款项%'
AND [STATE] = N'3'
ORDER BY [RECEIVE_TIME] DESC
"""
result = pd.read_sql(query, engine)
# 定义一个拆分函数
def split_subject(subject_str):
name, department, amount, description, dateidentifier = subject_str.split('-', 4)
return pd.Series({'姓名': name, '部门': department, '描述': description, '金额': amount, '日期+流水号': dateidentifier})
# 使用 apply 函数按行应用拆分函数
split_data = result.apply(lambda row: split_subject(row['SUBJECT']), axis=1)
# 将拆分后的数据连接回原始 DataFrame
result = pd.concat([result, split_data], axis=1)
# 选择需要导出的列
columns_to_export = ['姓名', '部门', '金额', '描述', '日期+流水号']
# 打印拆分后的结果
print(result[columns_to_export])
# 导出为 XLSX
result[columns_to_export].to_excel('提取刘的待办.xlsx', index=False) |