Home > Enterprise >  My list names are getting repetitive alongside my values
My list names are getting repetitive alongside my values

Time:06-08

I have been trying to print out the names of the features along with their corresponding values but I am getting repetition of my names along side the values. The values are as follows:

print(importance)
[-5.07573087e-01  1.41361595e 00 -7.62186274e-01 -8.91087742e-02
  2.18873995e-01  5.22420043e-02  1.95510634e 00 -1.14541803e 00
  2.23063723e-01  1.16037309e-02  8.77691010e-01  8.88617771e-01
 -6.84845807e-01  5.26310745e-01 -2.03825113e 00  4.52190443e 00
  5.01364675e-01 -4.68664684e 00 -5.22671627e 00 -1.31013919e 01
 -2.48262965e-01 -3.28450068e-02 -2.05078037e 00 -2.07719831e 00
  3.75180361e 00 -1.22410265e 00  1.27131566e 00 -2.28637429e 00
  4.04486539e-01  1.39317283e 00]

print(list_1)
['steelgrade', 'material_spec', 'hsm_temp_strip_coiling_meas_tail', 'hsm_temp_strip_exit_fm_meas_tail', 'ccm_casting_speed_tail', 'hsm_thickness_reduction_ratio_f1', 'tcm_deformation_total', 'tund_chem_boron', 'tund_chem_chromium', 'tund_chem_cobalt', 'tund_chem_manganese', 'tund_chem_molybdenum', 'tund_chem_titanium', 'tund_chem_vanadium', 'cgl_bridle_speed_3_meas_tail', 'cgl_temp_strip_dff_tail', 'cgl_temp_strip_z2_rc_tail', 'cgl_temp_strip_rtf_tail', 'cgl_temp_strip_sc_tail', 'cgl_temp_strip_soak_tail', 'cgl_elong_spm_tail', 'cgl_elong_tl_tail', 'cgl_thick_exit_meas_tail', 'cgl_wr_force_spm_head', 'cgl_wr_force_spm_body', 'cgl_wr_force_spm_tail', 'cgl_wr_force_spm_spec_head', 'cgl_wr_force_spm_spec_body', 'cgl_wr_force_spm_spec_tail', 'cgl_production_start_year']

The way I am trying to print it as follows:

for name in list_1:
    for i in(importance):
        print(f'Feature:{name},Score: %.5f' % i)

The result I am getting is as follows:

Feature:steelgrade,Score: -0.50757
Feature:steelgrade,Score: 1.41362
Feature:steelgrade,Score: -0.76219
Feature:steelgrade,Score: -0.08911
Feature:steelgrade,Score: 0.21887
Feature:steelgrade,Score: 0.05224
Feature:steelgrade,Score: 1.95511
Feature:steelgrade,Score: -1.14542
Feature:steelgrade,Score: 0.22306
Feature:steelgrade,Score: 0.01160
Feature:steelgrade,Score: 0.87769
Feature:steelgrade,Score: 0.88862
Feature:steelgrade,Score: -0.68485
Feature:steelgrade,Score: 0.52631
Feature:steelgrade,Score: -2.03825
Feature:steelgrade,Score: 4.52190
Feature:steelgrade,Score: 0.50136
Feature:steelgrade,Score: -4.68665
Feature:steelgrade,Score: -5.22672
Feature:steelgrade,Score: -13.10139
Feature:steelgrade,Score: -0.24826
Feature:steelgrade,Score: -0.03285
Feature:steelgrade,Score: -2.05078
Feature:steelgrade,Score: -2.07720
Feature:steelgrade,Score: 3.75180
Feature:steelgrade,Score: -1.22410
Feature:steelgrade,Score: 1.27132
Feature:steelgrade,Score: -2.28637
Feature:steelgrade,Score: 0.40449
Feature:steelgrade,Score: 1.39317
Feature:material_spec,Score: -0.50757
Feature:material_spec,Score: 1.41362
Feature:material_spec,Score: -0.76219
Feature:material_spec,Score: -0.08911
Feature:material_spec,Score: 0.21887
Feature:material_spec,Score: 0.05224
Feature:material_spec,Score: 1.95511
Feature:material_spec,Score: -1.14542
Feature:material_spec,Score: 0.22306
Feature:material_spec,Score: 0.01160
Feature:material_spec,Score: 0.87769
Feature:material_spec,Score: 0.88862
Feature:material_spec,Score: -0.68485
Feature:material_spec,Score: 0.52631
Feature:material_spec,Score: -2.03825
Feature:material_spec,Score: 4.52190
Feature:material_spec,Score: 0.50136
Feature:material_spec,Score: -4.68665
Feature:material_spec,Score: -5.22672
Feature:material_spec,Score: -13.10139
Feature:material_spec,Score: -0.24826
Feature:material_spec,Score: -0.03285
Feature:material_spec,Score: -2.05078
Feature:material_spec,Score: -2.07720
Feature:material_spec,Score: 3.75180
Feature:material_spec,Score: -1.22410
Feature:material_spec,Score: 1.27132
Feature:material_spec,Score: -2.28637
Feature:material_spec,Score: 0.40449
Feature:material_spec,Score: 1.39317
Feature:hsm_temp_strip_coiling_meas_tail,Score: -0.50757
Feature:hsm_temp_strip_coiling_meas_tail,Score: 1.41362
Feature:hsm_temp_strip_coiling_meas_tail,Score: -0.76219
Feature:hsm_temp_strip_coiling_meas_tail,Score: -0.08911
Feature:hsm_temp_strip_coiling_meas_tail,Score: 0.21887
Feature:hsm_temp_strip_coiling_meas_tail,Score: 0.05224
Feature:hsm_temp_strip_coiling_meas_tail,Score: 1.95511
Feature:hsm_temp_strip_coiling_meas_tail,Score: -1.14542
Feature:hsm_temp_strip_coiling_meas_tail,Score: 0.22306
Feature:hsm_temp_strip_coiling_meas_tail,Score: 0.01160
Feature:hsm_temp_strip_coiling_meas_tail,Score: 0.87769
Feature:hsm_temp_strip_coiling_meas_tail,Score: 0.88862
Feature:hsm_temp_strip_coiling_meas_tail,Score: -0.68485
Feature:hsm_temp_strip_coiling_meas_tail,Score: 0.52631
Feature:hsm_temp_strip_coiling_meas_tail,Score: -2.03825
Feature:hsm_temp_strip_coiling_meas_tail,Score: 4.52190
Feature:hsm_temp_strip_coiling_meas_tail,Score: 0.50136
Feature:hsm_temp_strip_coiling_meas_tail,Score: -4.68665
Feature:hsm_temp_strip_coiling_meas_tail,Score: -5.22672
Feature:hsm_temp_strip_coiling_meas_tail,Score: -13.10139
Feature:hsm_temp_strip_coiling_meas_tail,Score: -0.24826
Feature:hsm_temp_strip_coiling_meas_tail,Score: -0.03285
Feature:hsm_temp_strip_coiling_meas_tail,Score: -2.05078
Feature:hsm_temp_strip_coiling_meas_tail,Score: -2.07720
Feature:hsm_temp_strip_coiling_meas_tail,Score: 3.75180
Feature:hsm_temp_strip_coiling_meas_tail,Score: -1.22410
Feature:hsm_temp_strip_coiling_meas_tail,Score: 1.27132
Feature:hsm_temp_strip_coiling_meas_tail,Score: -2.28637
Feature:hsm_temp_strip_coiling_meas_tail,Score: 0.40449
Feature:hsm_temp_strip_coiling_meas_tail,Score: 1.39317
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: -0.50757
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: 1.41362
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: -0.76219
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: -0.08911
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: 0.21887
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: 0.05224
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: 1.95511
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: -1.14542
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: 0.22306
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: 0.01160
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: 0.87769
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: 0.88862
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: -0.68485
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: 0.52631
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: -2.03825
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: 4.52190
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: 0.50136
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: -4.68665
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: -5.22672
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: -13.10139
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: -0.24826
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: -0.03285
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: -2.05078
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: -2.07720
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: 3.75180
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: -1.22410
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: 1.27132
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: -2.28637
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: 0.40449
Feature:hsm_temp_strip_exit_fm_meas_tail,Score: 1.39317
Feature:ccm_casting_speed_tail,Score: -0.50757
Feature:ccm_casting_speed_tail,Score: 1.41362
Feature:ccm_casting_speed_tail,Score: -0.76219
Feature:ccm_casting_speed_tail,Score: -0.08911
Feature:ccm_casting_speed_tail,Score: 0.21887
Feature:ccm_casting_speed_tail,Score: 0.05224
Feature:ccm_casting_speed_tail,Score: 1.95511
Feature:ccm_casting_speed_tail,Score: -1.14542
Feature:ccm_casting_speed_tail,Score: 0.22306
Feature:ccm_casting_speed_tail,Score: 0.01160
Feature:ccm_casting_speed_tail,Score: 0.87769
Feature:ccm_casting_speed_tail,Score: 0.88862
Feature:ccm_casting_speed_tail,Score: -0.68485
Feature:ccm_casting_speed_tail,Score: 0.52631
Feature:ccm_casting_speed_tail,Score: -2.03825
Feature:ccm_casting_speed_tail,Score: 4.52190
Feature:ccm_casting_speed_tail,Score: 0.50136
Feature:ccm_casting_speed_tail,Score: -4.68665
Feature:ccm_casting_speed_tail,Score: -5.22672
Feature:ccm_casting_speed_tail,Score: -13.10139
Feature:ccm_casting_speed_tail,Score: -0.24826
Feature:ccm_casting_speed_tail,Score: -0.03285
Feature:ccm_casting_speed_tail,Score: -2.05078
Feature:ccm_casting_speed_tail,Score: -2.07720
Feature:ccm_casting_speed_tail,Score: 3.75180
Feature:ccm_casting_speed_tail,Score: -1.22410
Feature:ccm_casting_speed_tail,Score: 1.27132
Feature:ccm_casting_speed_tail,Score: -2.28637
Feature:ccm_casting_speed_tail,Score: 0.40449
Feature:ccm_casting_speed_tail,Score: 1.39317
Feature:hsm_thickness_reduction_ratio_f1,Score: -0.50757
Feature:hsm_thickness_reduction_ratio_f1,Score: 1.41362
Feature:hsm_thickness_reduction_ratio_f1,Score: -0.76219
Feature:hsm_thickness_reduction_ratio_f1,Score: -0.08911
Feature:hsm_thickness_reduction_ratio_f1,Score: 0.21887
Feature:hsm_thickness_reduction_ratio_f1,Score: 0.05224
Feature:hsm_thickness_reduction_ratio_f1,Score: 1.95511
Feature:hsm_thickness_reduction_ratio_f1,Score: -1.14542
Feature:hsm_thickness_reduction_ratio_f1,Score: 0.22306
Feature:hsm_thickness_reduction_ratio_f1,Score: 0.01160
Feature:hsm_thickness_reduction_ratio_f1,Score: 0.87769
Feature:hsm_thickness_reduction_ratio_f1,Score: 0.88862
Feature:hsm_thickness_reduction_ratio_f1,Score: -0.68485
Feature:hsm_thickness_reduction_ratio_f1,Score: 0.52631
Feature:hsm_thickness_reduction_ratio_f1,Score: -2.03825
Feature:hsm_thickness_reduction_ratio_f1,Score: 4.52190
Feature:hsm_thickness_reduction_ratio_f1,Score: 0.50136
Feature:hsm_thickness_reduction_ratio_f1,Score: -4.68665
Feature:hsm_thickness_reduction_ratio_f1,Score: -5.22672
Feature:hsm_thickness_reduction_ratio_f1,Score: -13.10139
Feature:hsm_thickness_reduction_ratio_f1,Score: -0.24826
Feature:hsm_thickness_reduction_ratio_f1,Score: -0.03285
Feature:hsm_thickness_reduction_ratio_f1,Score: -2.05078
Feature:hsm_thickness_reduction_ratio_f1,Score: -2.07720
Feature:hsm_thickness_reduction_ratio_f1,Score: 3.75180
Feature:hsm_thickness_reduction_ratio_f1,Score: -1.22410
Feature:hsm_thickness_reduction_ratio_f1,Score: 1.27132
Feature:hsm_thickness_reduction_ratio_f1,Score: -2.28637
Feature:hsm_thickness_reduction_ratio_f1,Score: 0.40449
Feature:hsm_thickness_reduction_ratio_f1,Score: 1.39317
Feature:tcm_deformation_total,Score: -0.50757
Feature:tcm_deformation_total,Score: 1.41362
Feature:tcm_deformation_total,Score: -0.76219
Feature:tcm_deformation_total,Score: -0.08911
Feature:tcm_deformation_total,Score: 0.21887
Feature:tcm_deformation_total,Score: 0.05224
Feature:tcm_deformation_total,Score: 1.95511
Feature:tcm_deformation_total,Score: -1.14542
Feature:tcm_deformation_total,Score: 0.22306
Feature:tcm_deformation_total,Score: 0.01160
Feature:tcm_deformation_total,Score: 0.87769
Feature:tcm_deformation_total,Score: 0.88862
Feature:tcm_deformation_total,Score: -0.68485
Feature:tcm_deformation_total,Score: 0.52631
Feature:tcm_deformation_total,Score: -2.03825
Feature:tcm_deformation_total,Score: 4.52190
Feature:tcm_deformation_total,Score: 0.50136
Feature:tcm_deformation_total,Score: -4.68665
Feature:tcm_deformation_total,Score: -5.22672
Feature:tcm_deformation_total,Score: -13.10139
Feature:tcm_deformation_total,Score: -0.24826
Feature:tcm_deformation_total,Score: -0.03285
Feature:tcm_deformation_total,Score: -2.05078
Feature:tcm_deformation_total,Score: -2.07720
Feature:tcm_deformation_total,Score: 3.75180
Feature:tcm_deformation_total,Score: -1.22410
Feature:tcm_deformation_total,Score: 1.27132
Feature:tcm_deformation_total,Score: -2.28637
Feature:tcm_deformation_total,Score: 0.40449
Feature:tcm_deformation_total,Score: 1.39317
Feature:tund_chem_boron,Score: -0.50757
Feature:tund_chem_boron,Score: 1.41362
Feature:tund_chem_boron,Score: -0.76219
Feature:tund_chem_boron,Score: -0.08911
Feature:tund_chem_boron,Score: 0.21887
Feature:tund_chem_boron,Score: 0.05224
Feature:tund_chem_boron,Score: 1.95511
Feature:tund_chem_boron,Score: -1.14542
Feature:tund_chem_boron,Score: 0.22306
Feature:tund_chem_boron,Score: 0.01160
Feature:tund_chem_boron,Score: 0.87769
Feature:tund_chem_boron,Score: 0.88862
Feature:tund_chem_boron,Score: -0.68485
Feature:tund_chem_boron,Score: 0.52631
Feature:tund_chem_boron,Score: -2.03825
Feature:tund_chem_boron,Score: 4.52190
Feature:tund_chem_boron,Score: 0.50136
Feature:tund_chem_boron,Score: -4.68665
Feature:tund_chem_boron,Score: -5.22672
Feature:tund_chem_boron,Score: -13.10139
Feature:tund_chem_boron,Score: -0.24826
Feature:tund_chem_boron,Score: -0.03285
Feature:tund_chem_boron,Score: -2.05078
Feature:tund_chem_boron,Score: -2.07720
Feature:tund_chem_boron,Score: 3.75180
Feature:tund_chem_boron,Score: -1.22410
Feature:tund_chem_boron,Score: 1.27132
Feature:tund_chem_boron,Score: -2.28637
Feature:tund_chem_boron,Score: 0.40449
Feature:tund_chem_boron,Score: 1.39317
Feature:tund_chem_chromium,Score: -0.50757
Feature:tund_chem_chromium,Score: 1.41362
Feature:tund_chem_chromium,Score: -0.76219
Feature:tund_chem_chromium,Score: -0.08911
Feature:tund_chem_chromium,Score: 0.21887
Feature:tund_chem_chromium,Score: 0.05224
Feature:tund_chem_chromium,Score: 1.95511
Feature:tund_chem_chromium,Score: -1.14542
Feature:tund_chem_chromium,Score: 0.22306
Feature:tund_chem_chromium,Score: 0.01160
Feature:tund_chem_chromium,Score: 0.87769
Feature:tund_chem_chromium,Score: 0.88862
Feature:tund_chem_chromium,Score: -0.68485
Feature:tund_chem_chromium,Score: 0.52631
Feature:tund_chem_chromium,Score: -2.03825
Feature:tund_chem_chromium,Score: 4.52190
Feature:tund_chem_chromium,Score: 0.50136
Feature:tund_chem_chromium,Score: -4.68665
Feature:tund_chem_chromium,Score: -5.22672
Feature:tund_chem_chromium,Score: -13.10139
Feature:tund_chem_chromium,Score: -0.24826
Feature:tund_chem_chromium,Score: -0.03285
Feature:tund_chem_chromium,Score: -2.05078
Feature:tund_chem_chromium,Score: -2.07720
Feature:tund_chem_chromium,Score: 3.75180
Feature:tund_chem_chromium,Score: -1.22410
Feature:tund_chem_chromium,Score: 1.27132
Feature:tund_chem_chromium,Score: -2.28637
Feature:tund_chem_chromium,Score: 0.40449
Feature:tund_chem_chromium,Score: 1.39317
Feature:tund_chem_cobalt,Score: -0.50757
Feature:tund_chem_cobalt,Score: 1.41362
Feature:tund_chem_cobalt,Score: -0.76219
Feature:tund_chem_cobalt,Score: -0.08911
Feature:tund_chem_cobalt,Score: 0.21887
Feature:tund_chem_cobalt,Score: 0.05224
Feature:tund_chem_cobalt,Score: 1.95511
Feature:tund_chem_cobalt,Score: -1.14542
Feature:tund_chem_cobalt,Score: 0.22306
Feature:tund_chem_cobalt,Score: 0.01160
Feature:tund_chem_cobalt,Score: 0.87769
Feature:tund_chem_cobalt,Score: 0.88862
Feature:tund_chem_cobalt,Score: -0.68485
Feature:tund_chem_cobalt,Score: 0.52631
Feature:tund_chem_cobalt,Score: -2.03825
Feature:tund_chem_cobalt,Score: 4.52190
Feature:tund_chem_cobalt,Score: 0.50136
Feature:tund_chem_cobalt,Score: -4.68665
Feature:tund_chem_cobalt,Score: -5.22672
Feature:tund_chem_cobalt,Score: -13.10139
Feature:tund_chem_cobalt,Score: -0.24826
Feature:tund_chem_cobalt,Score: -0.03285
Feature:tund_chem_cobalt,Score: -2.05078
Feature:tund_chem_cobalt,Score: -2.07720
Feature:tund_chem_cobalt,Score: 3.75180
Feature:tund_chem_cobalt,Score: -1.22410
Feature:tund_chem_cobalt,Score: 1.27132
Feature:tund_chem_cobalt,Score: -2.28637
Feature:tund_chem_cobalt,Score: 0.40449
Feature:tund_chem_cobalt,Score: 1.39317
Feature:tund_chem_manganese,Score: -0.50757
Feature:tund_chem_manganese,Score: 1.41362
Feature:tund_chem_manganese,Score: -0.76219
Feature:tund_chem_manganese,Score: -0.08911
Feature:tund_chem_manganese,Score: 0.21887
Feature:tund_chem_manganese,Score: 0.05224
Feature:tund_chem_manganese,Score: 1.95511
Feature:tund_chem_manganese,Score: -1.14542
Feature:tund_chem_manganese,Score: 0.22306
Feature:tund_chem_manganese,Score: 0.01160
Feature:tund_chem_manganese,Score: 0.87769
Feature:tund_chem_manganese,Score: 0.88862
Feature:tund_chem_manganese,Score: -0.68485
Feature:tund_chem_manganese,Score: 0.52631
Feature:tund_chem_manganese,Score: -2.03825
Feature:tund_chem_manganese,Score: 4.52190
Feature:tund_chem_manganese,Score: 0.50136
Feature:tund_chem_manganese,Score: -4.68665
Feature:tund_chem_manganese,Score: -5.22672
Feature:tund_chem_manganese,Score: -13.10139
Feature:tund_chem_manganese,Score: -0.24826
Feature:tund_chem_manganese,Score: -0.03285

The result is as above and the names of the features are getting repeated for each value. However, what I want is to make the name of the feature appear only once in the sequence for their corresponding value.

CodePudding user response:

This is happening because you're nesting the loop. So it first runs the second loop for each feature. You could try the following: for i, name in enumerate(list_1): print(f'Feature:{name},Score: %.5f' % importance[i])

CodePudding user response:

So I assume that the list importance and list_1 are of equal length and that every nth item in the list importance maps to the nth element in the list list_1.

You can easiliy loop through two arrays at the same time using the zip operator

for (value,property) in zip(importance, list_1):
    print(property   value)
  • Related