N_clarity=cross_table.shape[1]
时间: 2023-06-10 15:08:18 浏览: 46
这行代码的作用是计算 `cross_table` 的列数,将结果赋值给变量 `N_clarity`。具体来说,`cross_table.shape` 返回 `cross_table` 的维度,其中第一个元素是行数,第二个元素是列数,因此 `cross_table.shape[1]` 就是 `cross_table` 的列数。
相关问题
SELECT bs.report_no, bs.sample_id, bs.test_id, bs.service_type, bs.sample_name, bs.total_fee, bs.receivable_fee, bs.sample_no, bs.ranges, bs.grade, bs.sample_remark AS remark, bs.factory, bs.item_name, bs.apply_dept, bs.specification, bs.factory_number, bs.calibrat_point, bs.mandatory_flag, bs.inspection_type, bs.report_org_name, bs.plan_complete_date, bs.standard_instrument_name, bs.bleeding_site_name, bs.arrive_date, DATEDIFF( bs.plan_complete_date, NOW()) AS surplus_days, bs.order_no, bs.order_type, bs.customer_name, bs.order_id, bs.business_type, bs.group_id, bs.group_name, bs.item_id, bs.is_merge, bs.pass_time, bs.audit_time, bs.report_id, bs.compile_time, bs.generate_time, bs.pass_user_name, bs.audit_user_name, bs.compile_user_name, bs.report_state, bs.is_just_certificate, bs.label_price, bs.labor_cost, bs.product_type, bs.batch_number, bs.original_number, bs.type_no, bs.template_id, bs.template_version, bs.standard_instrument_id, bs.standard_instrument_name, bs.report_query_code, bs.test_user_id, bs.test_user_name, bs.test_time, bs.review_user_id, bs.review_user_name, bs.review_time, bs.or_number, bs.test_result, bs.test_result_text, bs.test_date, bs.test_address, bs.result_value, bs.unit, bs.test_dept_id, bs.test_dept_name, bs.sample_mass, bs.form, bs.color, bs.clarity, bs.amplification_detection, bs.precious_metal, bs.remarks, bs.photo, bs.identifying_code, bs.diamond_quality, bs.hand_ring, bs.craft, bs.instrument_photo, bs.customer_item_basis, bs.quality_photo, bs.check_point, bs.check_code, bs.mass_unit, bs.manufacturer_name, bs.manufacturer_addr, bs.result_sample_describe AS sampleDescribe, bs.test_rule AS metalRuleIdsStr, bsa.attach_id FROM view_sample_info bs JOIN bus_sample_report bsr ON bs.report_id = bsr.id JOIN bus_sample sa ON bsr.sample_id = sa.id JOIN bus_sample_attr bsa ON sa.id = bsa.id 需要按照bs.report_no 的整数来从小到大进行排序
你可以使用以下SQL语句来按照bs.report_no的整数值从小到大进行排序:
```sql
SELECT
bs.report_no,
bs.sample_id,
bs.test_id,
bs.service_type,
bs.sample_name,
bs.total_fee,
bs.receivable_fee,
bs.sample_no,
bs.ranges,
bs.grade,
bs.sample_remark AS remark,
bs.factory,
bs.item_name,
bs.apply_dept,
bs.specification,
bs.factory_number,
bs.calibrat_point,
bs.mandatory_flag,
bs.inspection_type,
bs.report_org_name,
bs.plan_complete_date,
bs.standard_instrument_name,
bs.bleeding_site_name,
bs.arrive_date,
DATEDIFF(bs.plan_complete_date, NOW()) AS surplus_days,
bs.order_no,
bs.order_type,
bs.customer_name,
bs.order_id,
bs.business_type,
bs.group_id,
bs.group_name,
bs.item_id,
bs.is_merge,
bs.pass_time,
bs.audit_time,
bs.report_id,
bs.compile_time,
bs.generate_time,
bs.pass_user_name,
bs.audit_user_name,
bs.compile_user_name,
bs.report_state,
bs.is_just_certificate,
bs.label_price,
bs.labor_cost,
bs.product_type,
bs.batch_number,
bs.original_number,
bs.type_no,
bs.template_id,
bs.template_version,
bs.standard_instrument_id,
bs.standard_instrument_name,
bs.report_query_code,
bs.test_user_id,
bs.test_user_name,
bs.test_time,
bs.review_user_id,
bs.review_user_name,
bs.review_time,
bs.or_number,
bs.test_result,
bs.test_result_text,
bs.test_date,
bs.test_address,
bs.result_value,
bs.unit,
bs.test_dept_id,
bs.test_dept_name,
bs.sample_mass,
bs.form,
bs.color,
bs.clarity,
bs.amplification_detection,
bs.precious_metal,
bs.remarks,
bs.photo,
bs.identifying_code,
bs.diamond_quality,
bs.hand_ring,
bs.craft,
bs.instrument_photo,
bs.customer_item_basis,
bs.quality_photo,
bs.check_point,
bs.check_code,
bs.mass_unit,
bs.manufacturer_name,
bs.manufacturer_addr,
bs.result_sample_describe AS sampleDescribe,
bs.test_rule AS metalRuleIdsStr,
bsa.attach_id
FROM
view_sample_info bs
JOIN bus_sample_report bsr ON bs.report_id = bsr.id
JOIN bus_sample sa ON bsr.sample_id = sa.id
JOIN bus_sample_attr bsa ON sa.id = bsa.id
ORDER BY CAST(bs.report_no AS UNSIGNED) ASC;
```
这将按照bs.report_no的整数值从小到大对结果进行排序。
diamonds = diamonds.drop('id', 'depth', 'table', 'x', 'y', 'z')cut_dict = {'Fair': 1, 'Good': 2, 'Very Good': 3, 'Premium': 4, 'Ideal': 5}color_dict = {'J': 1, 'I': 2, 'H': 3, 'G': 4, 'F': 5, 'E': 6, 'D': 7}clarity_dict = {'I1': 1, 'SI2': 2, 'SI1': 3, 'VS2': 4, 'VS1': 5, 'VVS2': 6, 'VVS1': 7, 'IF': 8}diamonds = diamonds.replace(cut_dict, subset='cut')diamonds = diamonds.replace(color_dict, subset='color')diamonds = diamonds.replace(clarity_dict, subset='clarity')这一部分出现错误不支持混合数据类型
这段代码的问题在于在使用`.replace()`函数时,传入了`subset`参数,但是该参数不适用于DataFrame的`.replace()`函数。正确的方式是使用字典的替换方法。例如,将该代码改写为如下形式:
```
diamonds = diamonds.drop(['id', 'depth', 'table', 'x', 'y', 'z'], axis=1)
cut_dict = {'Fair': 1, 'Good': 2, 'Very Good': 3, 'Premium': 4, 'Ideal': 5}
color_dict = {'J': 1, 'I': 2, 'H': 3, 'G': 4, 'F': 5, 'E': 6, 'D': 7}
clarity_dict = {'I1': 1, 'SI2': 2, 'SI1': 3, 'VS2': 4, 'VS1': 5, 'VVS2': 6, 'VVS1': 7, 'IF': 8}
diamonds['cut'] = diamonds['cut'].replace(cut_dict)
diamonds['color'] = diamonds['color'].replace(color_dict)
diamonds['clarity'] = diamonds['clarity'].replace(clarity_dict)
```
这样就能够正确地替换`cut`、`color`、`clarity`这三列的值了。