df = df[(df.vote_count >= 50) &(df.budget * df.revenue * df.popularity * df.vote_average !=0)].reset_index(drop = 'True')
时间: 2024-06-02 19:11:15 浏览: 122
这个代码的意思是筛选出 DataFrame df 中满足以下条件的行:
- vote_count 列的值大于等于 50;
- budget 列、revenue 列、popularity 列、vote_average 列的乘积不等于 0。
并将满足条件的行重新编号后返回一个新的 DataFrame。其中,reset_index 方法的参数 drop='True' 表示将原来的索引列丢弃,生成新的整数索引列。
相关问题
# Dataloader if webcam: show_vid = check_imshow() cudnn.benchmark = True # set True to speed up constant image size inference dataset = LoadStreams(source, img_size=imgsz, stride=stride) nr_sources = len(dataset.sources) else: dataset = LoadImages(source, img_size=imgsz, stride=stride) nr_sources = 1 vid_path, vid_writer, txt_path = [None] * nr_sources, [None] * nr_sources, [None] * nr_sources # initialize StrongSORT cfg = get_config() cfg.merge_from_file(opt.config_strongsort) # Create as many strong sort instances as there are video sources strongsort_list = [] for i in range(nr_sources): strongsort_list.append( StrongSORT( strong_sort_weights, device, half, max_dist=cfg.STRONGSORT.MAX_DIST, max_iou_distance=cfg.STRONGSORT.MAX_IOU_DISTANCE, max_age=cfg.STRONGSORT.MAX_AGE, n_init=cfg.STRONGSORT.N_INIT, nn_budget=cfg.STRONGSORT.NN_BUDGET, mc_lambda=cfg.STRONGSORT.MC_LAMBDA, ema_alpha=cfg.STRONGSORT.EMA_ALPHA,
这段代码是一个数据加载器(Dataloader)的实现。根据`webcam`变量的取值(True或False),选择不同的数据加载方式。
如果`webcam`为True,则使用`LoadStreams`类加载视频流数据,设置图像大小为`imgsz`,采样间隔为`stride`。同时,通过`check_imshow`函数检查是否可以使用`imshow`函数显示视频。
如果`webcam`为False,则使用`LoadImages`类加载图像数据,设置图像大小为`imgsz`,采样间隔为`stride`。
根据数据加载的方式,确定了数据集的数量`nr_sources`。
接下来,根据配置文件初始化StrongSORT(一种目标跟踪算法)。通过调用`get_config`函数获取配置信息,并将其合并到StrongSORT的配置中。
然后,根据视频源的数量创建相应数量的StrongSORT实例,并将它们存储在`strongsort_list`列表中。每个StrongSORT实例具有不同的参数设置,包括强排序权重、设备类型、是否使用半精度等。
最后,代码中还有一些关于StrongSORT参数的设置,如最大距离、最大IOU距离、最大年龄等等。这些参数可以根据具体需求进行调整。
优化这个sql SELECT count( 1 ) FROM ( SELECT B.ID, B.PURCHASE_REQUEST_ID, B.MATERIAL_ID, B.MATERIAL_CODE, B.MATERIAL_NAME, B.STANDARD, B.MODEL_ID, B.BILL_ROW_ID, B.BILL_NO, BILL_NAME, B.MODEL_CODE, B.MODEL_NAME, B.PARENT_MODEL_ID, B.PARENT_MODEL_CODE, B.PARENT_MODEL_NAME, B.UNIT_CODE, B.UNIT_NAME, B.PURCHASE_TYPE_CODE, CAST( NVL( B.APPLY_NUM, 0 ) AS NUMBER ( 24, 10 ) ) AS APPLY_NUM, CAST( NVL( B.DEAL_NUM, 0 ) AS NUMBER ( 24, 10 ) ) AS DEAL_NUM, CAST( NVL( B.RETURN_NUM, 0 ) AS NUMBER ( 24, 10 ) ) AS RETURN_NUM, B.DEAL_USER_ID, B.DEAL_USER_NAME, CAST( NVL( B.PRICE, 0 ) AS NUMBER ( 24, 10 ) ) AS PRICE, CAST( NVL( B.AMOUNT, 0 ) AS NUMBER ( 24, 10 ) ) AMOUNT, B.IMPLEMENT_CODE, B.IMPLEMENT_NAME, B.IMPLEMENT_INVEST_AMOUNT, B.PURCHASE_MANAGER_ID, B.PURCHASE_MANAGER_NAME, B.PROVIDER_ID, B.PROVIDER_NAME, B.REMARK, B.DELIVER_AREA, B.DELIVER_ADDRESS, B.RECEIVE_PEOPLE, B.RECEIVE_PEOPLE_PHONE, B.ITEM_STATUS, B.COST_CENTER, B.COST_BUDGET_CODE, B.COST_IMPLEMENT_NAME, B.FRAME_CONT_ID, B.FRAME_CONT_CODE, B.FRAME_CONT_NAME, B.DETAIL_CONFIG, B.PURCHASE_CATEGORY_CODE, B.INVOICE_TITLE_CODE, B.INVOICE_SEND_ADDRRSS, B.MATERIAL_REQUEST_ITEM_ID, B.YEAR, B.DELETE_FLAG, B.PROVINCE_CODE, B.REASON, B.PARENT_ITEM_ID, B.FRAME_CONT_ITEM_ID, B.SUB_MATERIAL_REQUEST_ID, B.SUB_MATERIAL_REQUEST_CODE, B.MATERIAL_URL, B.RECOMMEND_PROVIDER_NAMES, C.PURCHASE_REQUEST_CODE, C.PURCHASE_REQUEST_NAME, C.APPLY_TYPE_CODE, C.CREATOR_NAME, C.APPLY_TELEPHONE, C.COMPANY_NAME, C.DEPT_NAME, B.CREATE_TIME, TO_CHAR( B.CREATE_TIME, 'YYYY-MM-DD' ) CREATE_TIME_STR, C.ARRIVE_TIME, C.IS_TO_END, C.MONEY_WAY_CODE, C.OWN, C.APPLY_CATEGORY_CODE, C.manu_Type, C.BILL_ID, MMD.MATERIAL_TYPE_CODE, B.BRANCH_COMPANY_DEAL_USER_ID, B.BRANCH_COMPANY_DEAL_USER_NAME, ( SELECT ORG_NAME FROM ORGANIZATIONS WHERE DELETE_FLAG = '0' AND ORG_CODE = ( SELECT PARENT_COMPANY_NO FROM ORGANIZATIONS WHERE ID = B.MATERIAL_DEPT_ID )) AS MATERIAL_COMPANY_NAME, B.ORIGINAL, B.PROVIDER_PRODUCT_MODEL, B.PROVIDER_PRODUCT_NAME, B.PRODUCT_DESC, B.Back_Flag, CASE WHEN MMD.material_type_code = 'WZ' THEN '1' WHEN MMD.material_type_code = 'FW' THEN '2' ELSE '3' END apply_category_code_item, NVL( C.IS_CARDSYSTEM_REQUEST, '0' ) IS_CARDSYSTEM_REQUEST, B.APPLY_GROUP_AUTHORITES, B.SCIENTIFIC_RESEARCH_ID, B.SCIENTIFIC_RESEARCH_CODE, B.SCIENTIFIC_RESEARCH_NAME, B.PREQUALFY_CODE, nvl( C.IS_QUICK, '0' ) AS IS_QUICK, C.PURCHASE_WAY_CODE, C.PURCHASE_TYPE_CODE PURCHASE_TYPE_CODE_P, C.ORIGINAL_TYPE, C.PURCHASE_REQUEST_BILLS_TYPE, B.IS_FRAME_CONT_MONAD FROM PURCHASE_REQUEST_ITEM B LEFT JOIN PURCHASE_REQUEST C ON B.PURCHASE_REQUEST_ID = C.ID LEFT JOIN MATERIAL_DATA MMD ON MMD.ID = B.MATERIAL_ID AND MMD.DELETE_FLAG = '0' WHERE B.delete_flag = '0' AND B.Item_Status IN ( 1 ) AND NOT EXISTS ( SELECT * FROM purchase_request_item_log pril WHERE B.id = pril.purchase_request_item_id AND pril.lock_status = '1' AND pril.delete_flag = '0' ) AND ( ( c.apply_type_code NOT IN ( '20', '41', '3' ) AND nvl( B.Apply_Num, 0 ) > nvl( B.Deal_Num, 0 )) OR c.apply_type_code IN ( '20', '41', '3' ) ) AND B.Deal_User_Id =: 1 AND C.MONEY_WAY_CODE =: 2 AND C.APPLY_TYPE_CODE =: 3 AND C.PAY_OUT_TYPE_CODE =: 4 AND C.APPLY_CATEGORY_CODE =: 5 AND NVL( C.IS_CARDSYSTEM_REQUEST, '0' ) = : 6 AND NOT EXISTS ( SELECT * FROM purchase_request_item p left join material_province mp ON p.material_id = mp.material_id WHERE p.delete_flag = 0 AND mp.delete_flag = 0 AND mp.material_status = 03 AND mp.org_code = p.province_code AND p.id = B.id ) ORDER BY C.ID, B.ID ASC)
首先,可以将子查询中的所有列名改为别名,这样可以避免重名和提高代码可读性。另外,可以尝试使用 EXISTS 子查询来替换 NOT EXISTS 子查询,因为 EXISTS 子查询的性能通常更好。最后,可以考虑对 WHERE 子句中的多个条件进行逻辑上的分组,以避免出现过于复杂的条件表达式。下面是优化后的 SQL:
SELECT COUNT(1)
FROM (
SELECT
b.ID,
b.PURCHASE_REQUEST_ID,
b.MATERIAL_ID,
b.MATERIAL_CODE,
b.MATERIAL_NAME,
b.STANDARD,
b.MODEL_ID,
b.BILL_ROW_ID,
b.BILL_NO,
b.BILL_NAME,
b.MODEL_CODE,
b.MODEL_NAME,
b.PARENT_MODEL_ID,
b.PARENT_MODEL_CODE,
b.PARENT_MODEL_NAME,
b.UNIT_CODE,
b.UNIT_NAME,
b.PURCHASE_TYPE_CODE,
CAST(NVL(b.APPLY_NUM, 0) AS NUMBER(24, 10)) AS APPLY_NUM,
CAST(NVL(b.DEAL_NUM, 0) AS NUMBER(24, 10)) AS DEAL_NUM,
CAST(NVL(b.RETURN_NUM, 0) AS NUMBER(24, 10)) AS RETURN_NUM,
b.DEAL_USER_ID,
b.DEAL_USER_NAME,
CAST(NVL(b.PRICE, 0) AS NUMBER(24, 10)) AS PRICE,
CAST(NVL(b.AMOUNT, 0) AS NUMBER(24, 10)) AMOUNT,
b.IMPLEMENT_CODE,
b.IMPLEMENT_NAME,
b.IMPLEMENT_INVEST_AMOUNT,
b.PURCHASE_MANAGER_ID,
b.PURCHASE_MANAGER_NAME,
b.PROVIDER_ID,
b.PROVIDER_NAME,
b.REMARK,
b.DELIVER_AREA,
b.DELIVER_ADDRESS,
b.RECEIVE_PEOPLE,
b.RECEIVE_PEOPLE_PHONE,
b.ITEM_STATUS,
b.COST_CENTER,
b.COST_BUDGET_CODE,
b.COST_IMPLEMENT_NAME,
b.FRAME_CONT_ID,
b.FRAME_CONT_CODE,
b.FRAME_CONT_NAME,
b.DETAIL_CONFIG,
b.PURCHASE_CATEGORY_CODE,
b.INVOICE_TITLE_CODE,
b.INVOICE_SEND_ADDRRSS,
b.MATERIAL_REQUEST_ITEM_ID,
b.YEAR,
b.DELETE_FLAG,
b.PROVINCE_CODE,
b.REASON,
b.PARENT_ITEM_ID,
b.FRAME_CONT_ITEM_ID,
b.SUB_MATERIAL_REQUEST_ID,
b.SUB_MATERIAL_REQUEST_CODE,
b.MATERIAL_URL,
b.RECOMMEND_PROVIDER_NAMES,
c.PURCHASE_REQUEST_CODE,
c.PURCHASE_REQUEST_NAME,
c.APPLY_TYPE_CODE,
c.CREATOR_NAME,
c.APPLY_TELEPHONE,
c.COMPANY_NAME,
c.DEPT_NAME,
b.CREATE_TIME,
TO_CHAR(b.CREATE_TIME, 'YYYY-MM-DD') CREATE_TIME_STR,
c.ARRIVE_TIME,
c.IS_TO_END,
c.MONEY_WAY_CODE,
c.OWN,
c.APPLY_CATEGORY_CODE,
c.manu_Type,
c.BILL_ID,
MMD.MATERIAL_TYPE_CODE,
b.BRANCH_COMPANY_DEAL_USER_ID,
b.BRANCH_COMPANY_DEAL_USER_NAME,
(SELECT ORG_NAME FROM ORGANIZATIONS WHERE DELETE_FLAG = '0' AND ORG_CODE = (SELECT PARENT_COMPANY_NO FROM ORGANIZATIONS WHERE ID = b.MATERIAL_DEPT_ID)) AS MATERIAL_COMPANY_NAME,
b.ORIGINAL,
b.PROVIDER_PRODUCT_MODEL,
b.PROVIDER_PRODUCT_NAME,
b.PRODUCT_DESC,
b.Back_Flag,
CASE
WHEN MMD.material_type_code = 'WZ' THEN '1'
WHEN MMD.material_type_code = 'FW' THEN '2'
ELSE '3'
END apply_category_code_item,
NVL(c.IS_CARDSYSTEM_REQUEST, '0') IS_CARDSYSTEM_REQUEST,
b.APPLY_GROUP_AUTHORITES,
b.SCIENTIFIC_RESEARCH_ID,
b.SCIENTIFIC_RESEARCH_CODE,
b.SCIENTIFIC_RESEARCH_NAME,
b.PREQUALFY_CODE,
NVL(c.IS_QUICK, '0') AS IS_QUICK,
c.PURCHASE_WAY_CODE,
c.PURCHASE_TYPE_CODE PURCHASE_TYPE_CODE_P,
c.ORIGINAL_TYPE,
c.PURCHASE_REQUEST_BILLS_TYPE,
b.IS_FRAME_CONT_MONAD
FROM PURCHASE_REQUEST_ITEM b
LEFT JOIN PURCHASE_REQUEST c ON b.PURCHASE_REQUEST_ID = c.ID
LEFT JOIN MATERIAL_DATA MMD ON MMD.ID = b.MATERIAL_ID AND MMD.DELETE_FLAG = '0'
WHERE b.delete_flag = '0'
AND b.Item_Status IN (1)
AND b.Deal_User_Id = :1
AND C.MONEY_WAY_CODE = :2
AND C.APPLY_TYPE_CODE = :3
AND C.PAY_OUT_TYPE_CODE = :4
AND C.APPLY_CATEGORY_CODE = :5
AND NVL(C.IS_CARDSYSTEM_REQUEST, '0') = :6
AND EXISTS (
SELECT *
FROM purchase_request_item_log pril
WHERE B.id = pril.purchase_request_item_id
AND pril.lock_status = '1'
AND pril.delete_flag = '0'
)
AND (
c.apply_type_code IN ('20', '41', '3')
OR (
c.apply_type_code NOT IN ('20', '41', '3')
AND NVL(b.Apply_Num, 0) > NVL(b.Deal_Num, 0)
)
)
AND NOT EXISTS (
SELECT *
FROM purchase_request_item p
LEFT JOIN material_province mp ON p.material_id = mp.material_id
WHERE p.delete_flag = 0
AND mp.delete_flag = 0
AND mp.material_status = 03
AND mp.org_code = p.province_code
AND p.id = b.id
)
ORDER BY c.ID, b.ID ASC
)
阅读全文