【python while循环】while else 的使用

数据源data3.xlsx

编码  类   参数0 参数1 参数2 参数3 参数4 参数5 参数6
A1  1   200 54.0    1.9     0.7     11.2    0.2     0.7 
A2  1   100 3.0     0.3     0.1     11.8    0.0     0.0 
A3  1   100 54.0    7.7     0.8     12.5    0.3     0.8 
A4  1   100 13.0    0.5     0.3     13.1    0.8     0.4 
A5  1   120 20.0    2.3     1.2     11.7    0.1     0.1 
A6  1   80  11.0    3.2     1.6     25.5    0.1     0.0 
A7  2   100 8.0     2.6     1.4     11.6    0.1     0.0 
A8  2   100 2.0     6.4     1.5     7.9     1.1     3.3 
A9  2   100 38.0    4.8     0.5     15.4    0.2     0.5 
A10 2   150 2.0     0.2     0.0     16.7    0.1     0.0 
A11 2   90  24.0    3.1     3.2     18.0    0.1     0.0 
A12 2   90  13.9    3.0     1.8     19.2    0.1     0.8 
A13 2   120 13.3    3.0     1.9     20.5    0.4     0.7 
A14 2   100 12.6    2.9     2.0     21.7    0.2     0.7 
A15 3   100 12.0    2.8     2.2     23.0    1.4     0.7 
A16 3   150 11.3    2.8     2.3     24.3    1.5     0.7 
A17 3   120 10.7    2.7     2.4     25.5    0.5     0.7 
A18 3   120 10.0    2.7     2.5     26.8    0.0     0.8 
A19 3   110 9.4     2.6     2.7     28.1    3.2     0.8 
A20 3   80  8.7     2.6     2.8     29.3    1.8     0.8 
A21 3   100 8.1     2.5     2.9     30.6    1.9     0.1 
A22 3   100 7.4     2.5     3.0     31.8    0.2     0.1 
A23 3   100 6.8     2.4     3.2     33.1    0.2     0.1 
A24 3   150 6.2     2.4     3.3     34.4    0.2     0.4 
A25 3   90  5.5     2.3     3.4     35.6    0.2     0.2 
A26 3   90  4.9     2.2     3.5     36.9    0.2     1.4 
A27 3   120 4.2     2.2     3.6     38.2    0.2     1.5 
A28 3   100 2.4     2.1     3.8     39.4    0.2     0.9 
A29 1   105 1.6     2.3     3.9     39.1    0.8     0.8 
A30 1   105 0.8     2.3     4.0     40.2    0.8     0.8 
A31 1   105 0.0     2.3     4.2     41.3    0.8     0.8 
A32 1   105 0.9     2.2     4.3     42.4    0.8     0.8 
A33 2   105 1.7     2.2     4.4     43.5    0.9     0.8 
A34 2   105 2.5     2.2     4.5     44.6    0.9     0.8 
A35 2   100 3.4     2.1     4.6     45.7    0.9     0.8 
A36 2   100 4.2     2.1     4.8     46.7    0.9     0.8 
A37 2   100 5.0     2.1     4.9     47.8    0.9     0.8 
A38 2   100 5.9     2.1     5.0     48.9    0.9     0.8 
A39 2   100 6.7     2.0     5.1     50.0    0.9     0.8 
A40 2   100 7.5     2.0     5.3     51.1    1.0     0.9 
A41 3   100 8.4     2.0     5.4     52.2    1.0     0.9 
A42 3   100 9.2     1.9     5.5     53.3    1.0     0.9 
A43 3   100 10.0    1.9     5.6     54.4    1.0     0.9 
A44 3   95  10.9    1.9     5.8     55.4    1.0     0.9 
A45 3   95  11.7    1.9     5.9     56.5    1.0     0.9 
A46 3   95  12.5    1.8     6.0     57.6    1.1     0.9 
A47 3   95  13.4    1.8     6.1     58.7    1.1     0.9 
A48 3   95  14.2    1.8     6.3     59.8    1.1     0.9 
A49 1   95  15.0    1.7     6.4     60.9    1.1     0.9 
A50 1   95  15.9    1.7     6.5     62.0    1.1     0.9 
A51 1   95  16.7    1.7     6.6     63.1    1.1     1.0 
A52 1   95  17.5    1.6     6.8     64.2    1.2     1.0 
A53 2   95  18.4    1.6     6.9     65.2    1.2     1.0 
A54 2   90  19.2    1.6     7.0     66.3    1.2     1.0 
A55 2   90  20.0    1.6     7.1     67.4    1.2     1.0 
A56 2   90  20.9    1.5     7.3     68.5    1.2     1.0 
A57 2   90  21.7    1.5     7.4     69.6    1.2     1.0 
A58 2   90  22.5    1.5     7.5     70.7    1.3     1.0 
A59 2   90  23.4    1.4     7.6     71.8    1.3     1.0 
A60 2   90  24.2    1.4     7.8     72.9    1.3     1.0 
A61 3   90  25.0    1.4     7.9     73.9    1.3     1.1 
A62 3   90  25.9    1.4     8.0     75.0    1.3     1.1 
A63 3   90  26.7    1.3     8.1     76.1    1.3     1.1 
A64 3   85  27.5    1.3     8.3     77.2    1.4     1.1 
A65 3   85  28.4    1.3     8.4     78.3    1.4     1.1 
A66 3   85  29.2    1.2     8.5     79.4    1.4     1.1 
A67 3   85  30.0    1.2     8.6     80.5    1.4     1.1 
A68 3   85  30.9    1.2     8.8     81.6    1.4     1.1 
A69 2   100 16.3    4.3 8.3 92.3    1.3 1.3
A70 2   100 36.8    2.8 9.8 60.8    2.8 1.8
A71 3   100 16.9    0.9 4.9 65.9    2.9 1.9
A72 2   80  45.8    1.8 8.8 85.8    2.8 1.8
A73 1   60  38.8    2.8 8.8 86.8    1.8 1.8
A74 3   100 42.1    0.1 7.1 73.1    2.1 1.1
A75 3   100 12.3    0.3 4.3 80.3    2.3 1.3
A76 1   100 32.1    1.1 4.1 60.1    1.1 1.1
A77 2   100 47.3    1.3 6.3 70.3    1.3 1.3
A78 2   100 37.1    3.1 5.1 63.1    2.1 1.1
A79 3   120 46.3    3.3 9.3 92.3    1.3 1.3
A80 2   100 30.4    1.4 4.4 60.4    1.4 1.4
A81 1   100 24.9    2.9 8.9 83.9    2.9 1.9
A82 2   100 27.1    0.1 4.1 59.1    2.1 1.1
A83 2   100 21.9    0.9 4.9 63.9    1.9 1.9
A84 2   100 28.1    3.1 9.1 78.1    2.1 1.1
A85 2   100 44.2    0.2 8.2 73.2    1.2 1.2
A86 2   80  37.1    3.1 4.1 88.1    1.1 1.1
A87 2   60  15.2    1.2 6.2 74.2    2.2 1.2
A88 2   100 16.7    4.7 4.7 78.7    1.7 1.7
A89 3   100 30.9    0.9 6.9 59.9    1.9 1.9
A90 1   100 12.9    2.9 5.9 69.9    1.9 1.9
A91 3   100 31.4    3.4 6.4 60.4    2.4 1.4
A92 3   100 15.7    4.7 4.7 69.7    1.7 1.7
A93 1   100 33.5    1.5 4.5 88.5    1.5 1.5
A94 2   100 19.7    0.7 9.7 84.7    2.7 1.7
A95 1   100 44.5    2.5 7.5 59.5    2.5 1.5
A96 1   100 10.8    0.8 9.8 70.8    1.8 1.8
A97 3   100 46.5    0.5 6.5 61.5    1.5 1.5
A98 2   100 10.2    0.2 4.2 87.2    2.2 1.2
A99 1   100 22.3    3.3 8.3 91.3    1.3 1.3
A100    1   100 28.2    1.2 9.2 78.2    1.2 1.2
A101    2   100 31.7    0.7 9.7 98.7    2.7 1.7
A102    2   100 35.4    3.4 6.4 62.4    2.4 1.4
A103    2   100 40.7    3.7 4.7 81.7    1.7 1.7
A104    3   100 28.7    1.7 4.7 87.7    2.7 1.7
A105    2   80  30.7    0.7 7.7 86.7    2.7 1.7
A106    3   60  45.2    2.2 4.2 99.2    2.2 1.2
A107    1   100 42.3    1.3 8.3 72.3    1.3 1.3
A108    3   100 38.4    1.4 4.4 95.4    1.4 1.4
A109    3   100 19.5    2.5 9.5 67.5    2.5 1.5
A110    2   100 24.2    2.2 8.2 66.2    1.2 1.2
A111    2   100 32.2    4.2 7.2 60.2    2.2 1.2
A112    2   120 34.7    0.7 7.7 96.7    1.7 1.7
A113    1   100 35.4    4.4 9.4 61.4    2.4 1.4
A114    1   100 40.2    0.2 4.2 97.2    2.2 1.2
A115    2   100 38.6    0.6 7.6 71.6    1.6 1.6
A116    2   100 40.1    3.1 9.1 89.1    1.1 1.1
A117    2   100 26.0    2   7   67  2   1
A118    1   100 28.6    3.6 4.6 94.6    2.6 1.6
A119    1   100 13.4    1.4 4.4 76.4    2.4 1.4
A120    2   100 24.3    0.3 6.3 94.3    2.3 1.3
A121    1   100 13.3    3.3 4.3 73.3    2.3 1.3
A122    1   100 32.2    2.2 7.2 94.2    1.2 1.2
A123    1   100 30.6    4.6 4.6 61.6    2.6 1.6
A124    1   100 10.0    0   9   93  2   1
A125    3   100 45.5    0.5 4.5 99.5    2.5 1.5
A126    3   100 26.6    0.6 9.6 92.6    1.6 1.6
A127    2   100 20.2    3.2 8.2 93.2    2.2 1.2
A128    3   100 21.3    4.3 7.3 67.3    1.3 1.3
A129    2   100 13.8    2.8 8.8 84.8    1.8 1.8
A130    3   100 14.2    4.2 4.2 97.2    2.2 1.2
A131    3   100 25.9    0.9 7.9 94.9    1.9 1.9
A132    3   100 17.9    1.9 9.9 63.9    2.9 1.9
A133    1   90  19.9    4.9 7.9 86.9    2.9 1.9
A134    1   100 39.1    0.1 6.1 61.1    2.1 1.1
A135    1   100 47.7    1.7 6.7 62.7    2.7 1.7
A136    2   100 35.3    3.3 7.3 79.3    2.3 1.3
A137    3   100 15.3    3.3 8.3 69.3    1.3 1.3
A138    3   100 17.6    0.6 5.6 87.6    2.6 1.6
A139    1   100 31.2    4.2 9.2 70.2    2.2 1.2
A140    2   100 13.3    0.3 9.3 80.3    2.3 1.3
A141    2   100 13.2    1.2 7.2 70.2    2.2 1.2
A142    1   100 44.6    4.6 5.6 71.6    2.6 1.6
A143    3   100 30.1    2.1 5.1 70.1    2.1 1.1
A144    2   100 42.2    2.2 8.2 89.2    1.2 1.2
A145    2   100 25.4    4.4 7.4 88.4    1.4 1.4
A146    2   100 12.3    4.3 8.3 84.3    2.3 1.3
A147    3   100 14.7    4.7 7.7 83.7    2.7 1.7
A148    2   100 23.1    2.1 9.1 98.1    2.1 1.1
A149    3   100 32.6    3.6 6.6 94.6    2.6 1.6
A150    1   100 14.6    1.6 9.6 88.6    2.6 1.6
A151    1   100 36.0    2   8   82  3   2
A152    1   100 22.9    4.9 9.9 97.9    2.9 1.9
A153    2   100 35.1    1.1 5.1 88.1    2.1 1.1
A154    2   100 34.3    0.3 9.3 95.3    1.3 1.3
A155    3   100 28.9    0.9 6.9 87.9    1.9 1.9
A156    1   100 38.5    4.5 6.5 70.5    1.5 1.5
A157    3   100 44.8    3.8 7.8 73.8    2.8 1.8
A158    3   100 45.8    4.8 4.8 73.8    1.8 1.8
A159    3   100 10.4    3.4 4.4 92.4    2.4 1.4
A160    1   100 47.0    1   8   63  1   1
A161    2   100 17.3    2.3 7.3 70.3    2.3 1.3
A162    2   100 30.2    4.2 7.2 67.2    2.2 1.2
A163    3   90  41.2    0.2 4.2 68.2    1.2 1.2
A164    2   100 10.3    0.3 7.3 96.3    1.3 1.3
A165    3   100 12.4    3.4 8.4 86.4    1.4 1.4
A166    3   100 26.3    3.3 7.3 62.3    1.3 1.3
A167    3   100 10.4    3.4 5.4 73.4    1.4 1.4
A168    3   100 25.3    4.3 6.3 73.3    1.3 1.3
A169    3   100 42.5    3.5 7.5 79.5    1.5 1.5
A170    2   100 44.7    4.7 8.7 61.7    1.7 1.7
A171    1   100 44.5    3.5 9.5 70.5    1.5 1.5
A172    2   100 42.1    4.1 6.1 89.1    2.1 1.1
A173    1   100 32.7    0.7 7.7 69.7    2.7 1.7
A174    2   100 14.7    4.7 5.7 85.7    1.7 1.7
A175    2   100 16.9    4.9 9.9 91.9    2.9 1.9
A176    3   100 17.7    4.7 8.7 85.7    1.7 1.7
A177    2   100 32.8    2.8 9.8 59.8    1.8 1.8
A178    1   100 37.8    1.8 7.8 71.8    1.8 1.8
A179    1   100 16.7    2.7 9.7 60.7    1.7 1.7
A180    1   100 13.0    0   8   91  1   1
A181    3   100 26.2    1.2 5.2 77.2    2.2 1.2
A182    1   100 36.1    3.1 7.1 89.1    2.1 1.1
A183    3   100 16.2    4.2 4.2 67.2    2.2 1.2
A184    1   100 20.5    1.5 6.5 93.5    1.5 1.5
A185    1   100 12.1    3.1 6.1 62.1    1.1 1.1
A186    1   100 20.1    2.1 6.1 87.1    1.1 1.1
A187    2   100 42.2    2.2 6.2 60.2    2.2 1.2
A188    3   100 44.8    2.8 8.8 98.8    1.8 1.8
A189    1   100 10.9    1.9 4.9 65.9    1.9 1.9
A190    1   100 37.4    0.4 4.4 98.4    1.4 1.4
A191    3   100 31.8    1.8 8.8 79.8    2.8 1.8
A192    1   100 41.3    4.3 7.3 84.3    1.3 1.3
A193    3   90  44.3    3.3 8.3 64.3    2.3 1.3
A194    1   100 17.8    0.8 5.8 97.8    2.8 1.8
A195    1   100 32.6    1.6 8.6 98.6    1.6 1.6
A196    2   100 27.8    4.8 9.8 65.8    1.8 1.8
A197    2   100 22.1    2.1 9.1 77.1    1.1 1.1
A198    3   100 23.9    3.9 5.9 93.9    2.9 1.9
A199    2   100 13.3    1.3 9.3 70.3    2.3 1.3
A200    3   100 32.4    1.4 9.4 97.4    2.4 1.4
A201    2   100 27.4    1.4 6.4 94.4    2.4 1.4
A202    1   100 10.4    1.4 8.4 73.4    2.4 1.4
A203    2   100 23.1    3.1 4.1 80.1    2.1 1.1
A204    1   2   42.3    4.3 4.3 69.3    2.3 1.3
A205    1   2   27.4    2.4 9.4 66.4    1.4 1.4
A206    1   2   37.7    4.7 8.7 83.7    1.7 1.7
A207    2   3   24.6    4.6 7.6 92.6    2.6 1.6
A208    1   3   21.0    3   5   91  1   1
A209    1   3   39.3    1.3 5.3 94.3    2.3 1.3
A210    3   10  21.3    3.3 8.3 66.3    2.3 1.3
A211    2   1.5 38.9    0.9 8.9 77.9    2.9 1.9
A212    3   1.5 32.3    2.3 8.3 94.3    2.3 1.3
A213    1   1.5 35.1    4.1 6.1 93.1    1.1 1.1
A214    1   20  11.7    4.7 5.7 95.7    1.7 1.7
A215    2   100 17.8    0.8 9.8 76.8    2.8 1.8
A216    2   30  31.7    2.7 5.7 66.7    2.7 1.7
A217    3   20  40.9    0.9 8.9 82.9    1.9 1.9
A218    1   100 12.0    2   7   60  3   2
A219    1   100 30.5    3.5 9.5 74.5    2.5 1.5
A220    3   100 10.8    1.8 5.8 78.8    1.8 1.8
A221    1   20  13.9    0.9 4.9 87.9    1.9 1.9
A222    3   20  28.5    2.5 4.5 78.5    1.5 1.5
A223    3   20  29.3    0.3 5.3 90.3    1.3 1.3
A224    2   30  39.9    3.9 5.9 72.9    1.9 1.9
A225    1   20  26.8    0.8 9.8 66.8    1.8 1.8
A226    2   100 37.8    4.8 6.8 82.8    1.8 1.8
A227    3   100 38.7    1.7 8.7 76.7    1.7 1.7
A228    1   100 38.7    3.7 4.7 60.7    2.7 1.7
A229    3   20  35.8    3.8 4.8 61.8    1.8 1.8
A230    1   20  46.8    1.8 9.8 99.8    2.8 1.8
A231    3   20  22.4    3.4 9.4 77.4    1.4 1.4
A232    1   80  30.0    4   6   85  1   1
A233    3   40  43.1    2.1 6.1 69.1    1.1 1.1
A234    2   40  41.6    4.6 6.6 93.6    2.6 1.6
A235    1   50  31.5    4.5 9.5 98.5    1.5 1.5
A236    3   30  12.6    4.6 8.6 84.6    1.6 1.6
A237    2   40  32.9    0.9 8.9 60.9    2.9 1.9
A238    2   100 37.7    1.7 9.7 93.7    2.7 1.7
A239    3   30  35.7    3.7 8.7 68.7    1.7 1.7
A240    1   70  14.0    0   9   80  2   1

运行结果:

"D:\Program Files\Python27\python.exe" D:/PycharmProjects/learn2018/数据处理1.py
***********************参数1**************************************
1091.93761141
A30 105.0
A8 100.0
A21 100.0
***********************参数2**************************************
282.277895066
A221 20.0
A35 100.0
A125 100.0
***********************参数3**************************************
322.416666667
A213 1.5
A207 3.0
A21 100.0
***********************参数4**************************************
7193.7
A204 2.0
A234 40.0
A23 100.0
***********************参数5**************************************
32.35
A2 100.0
A211 1.5
A223 20.0
***********************参数6**************************************
17.45
A5 120.0
A211 1.5
A22 100.0

Process finished with exit code 0

源代码

#-*- coding:utf-8 -*-

import sys
reload(sys)
sys.setdefaultencoding('utf-8')

import time
time1=time.time()
import pandas as pd
import random
import  numpy as np


##读取数据
df=pd.read_excel("C:/pic/data/data3.xlsx")




####################各个参数的求和值范围
t1_max=1300
t1_min=1000

t2_max=320
t2_min=280

t3_max=350
t3_min=300

t4_max=8000
t4_min=6000

t5_max=40
t5_min=30

t6_max=20
t6_min=15







##########################################参数1###################################################
print u'***********************参数1**************************************'
df['k1']=0
# print df
m1=df[df[u'类']==1]

m2=df[df[u'类']==2]
m3=df[df[u'类']==3]

# print m1.index.tolist()
#
# print m2.index.tolist()
#
# print m3.index.tolist()



###################随机选择
random_m1=random.sample(m1.index.tolist(), 1)[0]
random_m2=random.sample(m2.index.tolist(), 1)[0]
random_m3=random.sample(m3.index.tolist(), 1)[0]

# print random_m1,random_m2,random_m3


##########一共标出3个1

df.iloc[random_m1,9]=1
df.iloc[random_m2,9]=1

df.iloc[random_m3,9]=1


###########计算Q
df['Q']=df['k1']*df[u'参数0']

# print df


##########计算T

#####参数1求和
prod = map(lambda (a,b):a*b, zip(df[u'参数1'].tolist(),df['Q'].tolist()))

sum_prod=sum(prod)

# print sum_prod



while sum_prod>t1_max or sum_prod<t1_min:

    df['k1'] = 0
    m1 = df[df[u'类'] == 1]
    m2 = df[df[u'类'] == 2]
    m3 = df[df[u'类'] == 3]
    ###################随机选择
    random_m1 = random.sample(m1.index.tolist(), 1)[0]
    random_m2 = random.sample(m2.index.tolist(), 1)[0]
    random_m3 = random.sample(m3.index.tolist(), 1)[0]



    ##########一共标出3个1

    df.iloc[random_m1, 9] = 1
    df.iloc[random_m2, 9] = 1

    df.iloc[random_m3, 9] = 1

    ###########计算Q
    df['Q'] = df['k1'] * df[u'参数0']

    ##########计算T

    #####参数1求和
    prod = map(lambda (a, b): a * b, zip(df[u'参数1'].tolist(), df['Q'].tolist()))

    sum_prod = sum(prod)

    # print random_m1, random_m2, random_m3,sum_prod

else:
    print sum_prod
    print df.iloc[random_m1,0],df.iloc[random_m1,2]
    print df.iloc[random_m2, 0], df.iloc[random_m2, 2]
    print df.iloc[random_m3, 0], df.iloc[random_m3, 2]






##########################################参数2###################################################
print u'***********************参数2**************************************'
df['k1']=0
# print df
m1=df[df[u'类']==1]

m2=df[df[u'类']==2]
m3=df[df[u'类']==3]

# print m1.index.tolist()
#
# print m2.index.tolist()
#
# print m3.index.tolist()



###################随机选择
random_m1=random.sample(m1.index.tolist(), 1)[0]
random_m2=random.sample(m2.index.tolist(), 1)[0]
random_m3=random.sample(m3.index.tolist(), 1)[0]

# print random_m1,random_m2,random_m3


##########一共标出3个1

df.iloc[random_m1,9]=1
df.iloc[random_m2,9]=1

df.iloc[random_m3,9]=1


###########计算Q
df['Q']=df['k1']*df[u'参数0']

# print df


##########计算T

#####参数1求和
prod = map(lambda (a,b):a*b, zip(df[u'参数2'].tolist(),df['Q'].tolist()))

sum_prod=sum(prod)

# print sum_prod



while sum_prod>t2_max or sum_prod<t2_min:

    df['k1'] = 0
    m1 = df[df[u'类'] == 1]
    m2 = df[df[u'类'] == 2]
    m3 = df[df[u'类'] == 3]
    ###################随机选择
    random_m1 = random.sample(m1.index.tolist(), 1)[0]
    random_m2 = random.sample(m2.index.tolist(), 1)[0]
    random_m3 = random.sample(m3.index.tolist(), 1)[0]



    ##########一共标出3个1

    df.iloc[random_m1, 9] = 1
    df.iloc[random_m2, 9] = 1

    df.iloc[random_m3, 9] = 1

    ###########计算Q
    df['Q'] = df['k1'] * df[u'参数0']

    ##########计算T

    #####参数1求和
    prod = map(lambda (a, b): a * b, zip(df[u'参数2'].tolist(), df['Q'].tolist()))

    sum_prod = sum(prod)

    # print random_m1, random_m2, random_m3,sum_prod

else:
    print sum_prod
    print df.iloc[random_m1,0],df.iloc[random_m1,2]
    print df.iloc[random_m2, 0], df.iloc[random_m2, 2]
    print df.iloc[random_m3, 0], df.iloc[random_m3, 2]




##########################################参数3###################################################
print u'***********************参数3**************************************'
df['k1']=0
# print df
m1=df[df[u'类']==1]

m2=df[df[u'类']==2]
m3=df[df[u'类']==3]

# print m1.index.tolist()
#
# print m2.index.tolist()
#
# print m3.index.tolist()



###################随机选择
random_m1=random.sample(m1.index.tolist(), 1)[0]
random_m2=random.sample(m2.index.tolist(), 1)[0]
random_m3=random.sample(m3.index.tolist(), 1)[0]

# print random_m1,random_m2,random_m3


##########一共标出3个1

df.iloc[random_m1,9]=1
df.iloc[random_m2,9]=1

df.iloc[random_m3,9]=1


###########计算Q
df['Q']=df['k1']*df[u'参数0']

# print df


##########计算T

#####参数1求和
prod = map(lambda (a,b):a*b, zip(df[u'参数3'].tolist(),df['Q'].tolist()))

sum_prod=sum(prod)

# print sum_prod



while sum_prod>t3_max or sum_prod<t3_min:

    df['k1'] = 0
    m1 = df[df[u'类'] == 1]
    m2 = df[df[u'类'] == 2]
    m3 = df[df[u'类'] == 3]
    ###################随机选择
    random_m1 = random.sample(m1.index.tolist(), 1)[0]
    random_m2 = random.sample(m2.index.tolist(), 1)[0]
    random_m3 = random.sample(m3.index.tolist(), 1)[0]



    ##########一共标出3个1

    df.iloc[random_m1, 9] = 1
    df.iloc[random_m2, 9] = 1

    df.iloc[random_m3, 9] = 1

    ###########计算Q
    df['Q'] = df['k1'] * df[u'参数0']

    ##########计算T

    #####参数1求和
    prod = map(lambda (a, b): a * b, zip(df[u'参数3'].tolist(), df['Q'].tolist()))

    sum_prod = sum(prod)

    # print random_m1, random_m2, random_m3,sum_prod

else:
    print sum_prod
    print df.iloc[random_m1,0],df.iloc[random_m1,2]
    print df.iloc[random_m2, 0], df.iloc[random_m2, 2]
    print df.iloc[random_m3, 0], df.iloc[random_m3, 2]




##########################################参数4###################################################
print u'***********************参数4**************************************'
df['k1']=0
# print df
m1=df[df[u'类']==1]

m2=df[df[u'类']==2]
m3=df[df[u'类']==3]

# print m1.index.tolist()
#
# print m2.index.tolist()
#
# print m3.index.tolist()



###################随机选择
random_m1=random.sample(m1.index.tolist(), 1)[0]
random_m2=random.sample(m2.index.tolist(), 1)[0]
random_m3=random.sample(m3.index.tolist(), 1)[0]

# print random_m1,random_m2,random_m3


##########一共标出3个1

df.iloc[random_m1,9]=1
df.iloc[random_m2,9]=1

df.iloc[random_m3,9]=1


###########计算Q
df['Q']=df['k1']*df[u'参数0']

# print df


##########计算T

#####参数1求和
prod = map(lambda (a,b):a*b, zip(df[u'参数4'].tolist(),df['Q'].tolist()))

sum_prod=sum(prod)

# print sum_prod



while sum_prod>t4_max or sum_prod<t4_min:

    df['k1'] = 0
    m1 = df[df[u'类'] == 1]
    m2 = df[df[u'类'] == 2]
    m3 = df[df[u'类'] == 3]
    ###################随机选择
    random_m1 = random.sample(m1.index.tolist(), 1)[0]
    random_m2 = random.sample(m2.index.tolist(), 1)[0]
    random_m3 = random.sample(m3.index.tolist(), 1)[0]



    ##########一共标出3个1

    df.iloc[random_m1, 9] = 1
    df.iloc[random_m2, 9] = 1

    df.iloc[random_m3, 9] = 1

    ###########计算Q
    df['Q'] = df['k1'] * df[u'参数0']

    ##########计算T

    #####参数1求和
    prod = map(lambda (a, b): a * b, zip(df[u'参数4'].tolist(), df['Q'].tolist()))

    sum_prod = sum(prod)

    # print random_m1, random_m2, random_m3,sum_prod

else:
    print sum_prod
    print df.iloc[random_m1,0],df.iloc[random_m1,2]
    print df.iloc[random_m2, 0], df.iloc[random_m2, 2]
    print df.iloc[random_m3, 0], df.iloc[random_m3, 2]





##########################################参数5###################################################
print u'***********************参数5**************************************'
df['k1']=0
# print df
m1=df[df[u'类']==1]

m2=df[df[u'类']==2]
m3=df[df[u'类']==3]

# print m1.index.tolist()
#
# print m2.index.tolist()
#
# print m3.index.tolist()



###################随机选择
random_m1=random.sample(m1.index.tolist(), 1)[0]
random_m2=random.sample(m2.index.tolist(), 1)[0]
random_m3=random.sample(m3.index.tolist(), 1)[0]

# print random_m1,random_m2,random_m3


##########一共标出3个1

df.iloc[random_m1,9]=1
df.iloc[random_m2,9]=1

df.iloc[random_m3,9]=1


###########计算Q
df['Q']=df['k1']*df[u'参数0']

# print df


##########计算T

#####参数1求和
prod = map(lambda (a,b):a*b, zip(df[u'参数5'].tolist(),df['Q'].tolist()))

sum_prod=sum(prod)

# print sum_prod



while sum_prod>t5_max or sum_prod<t5_min:

    df['k1'] = 0
    m1 = df[df[u'类'] == 1]
    m2 = df[df[u'类'] == 2]
    m3 = df[df[u'类'] == 3]
    ###################随机选择
    random_m1 = random.sample(m1.index.tolist(), 1)[0]
    random_m2 = random.sample(m2.index.tolist(), 1)[0]
    random_m3 = random.sample(m3.index.tolist(), 1)[0]



    ##########一共标出3个1

    df.iloc[random_m1, 9] = 1
    df.iloc[random_m2, 9] = 1

    df.iloc[random_m3, 9] = 1

    ###########计算Q
    df['Q'] = df['k1'] * df[u'参数0']

    ##########计算T

    #####参数1求和
    prod = map(lambda (a, b): a * b, zip(df[u'参数5'].tolist(), df['Q'].tolist()))

    sum_prod = sum(prod)

    # print random_m1, random_m2, random_m3,sum_prod

else:
    print sum_prod
    print df.iloc[random_m1,0],df.iloc[random_m1,2]
    print df.iloc[random_m2, 0], df.iloc[random_m2, 2]
    print df.iloc[random_m3, 0], df.iloc[random_m3, 2]




##########################################参数6###################################################
print u'***********************参数6**************************************'
df['k1']=0
# print df
m1=df[df[u'类']==1]

m2=df[df[u'类']==2]
m3=df[df[u'类']==3]

# print m1.index.tolist()
#
# print m2.index.tolist()
#
# print m3.index.tolist()



###################随机选择
random_m1=random.sample(m1.index.tolist(), 1)[0]
random_m2=random.sample(m2.index.tolist(), 1)[0]
random_m3=random.sample(m3.index.tolist(), 1)[0]

# print random_m1,random_m2,random_m3


##########一共标出3个1

df.iloc[random_m1,9]=1
df.iloc[random_m2,9]=1

df.iloc[random_m3,9]=1


###########计算Q
df['Q']=df['k1']*df[u'参数0']

# print df


##########计算T

#####参数1求和
prod = map(lambda (a,b):a*b, zip(df[u'参数6'].tolist(),df['Q'].tolist()))

sum_prod=sum(prod)

# print sum_prod



while sum_prod>t6_max or sum_prod<t6_min:

    df['k1'] = 0
    m1 = df[df[u'类'] == 1]
    m2 = df[df[u'类'] == 2]
    m3 = df[df[u'类'] == 3]
    ###################随机选择
    random_m1 = random.sample(m1.index.tolist(), 1)[0]
    random_m2 = random.sample(m2.index.tolist(), 1)[0]
    random_m3 = random.sample(m3.index.tolist(), 1)[0]



    ##########一共标出3个1

    df.iloc[random_m1, 9] = 1
    df.iloc[random_m2, 9] = 1

    df.iloc[random_m3, 9] = 1

    ###########计算Q
    df['Q'] = df['k1'] * df[u'参数0']

    ##########计算T

    #####参数1求和
    prod = map(lambda (a, b): a * b, zip(df[u'参数6'].tolist(), df['Q'].tolist()))

    sum_prod = sum(prod)

    # print random_m1, random_m2, random_m3,sum_prod

else:
    print sum_prod
    print df.iloc[random_m1,0],df.iloc[random_m1,2]
    print df.iloc[random_m2, 0], df.iloc[random_m2, 2]
    print df.iloc[random_m3, 0], df.iloc[random_m3, 2]


E列有未知个数和位置的1,2,3数值
在E列所有显示为1的旁边,随机某个单元格标出1个1
在E列所有显示为2的旁边,随机某个单元格标出1个1
在E列所有显示为3的旁边,随机某个单元格标出1个1
一共标出3个1
显示结果如F列举例 每点一次刷新或计算,F列标1的位置随机变化
F列随机标出3个1后在Q列和T列进行计算,直至T列的求和结果界于W列和X列所列的数值之间,则计算完毕,将符合计算结果的选中的3个编码和参数0显示于Z列和AA列。否则不停随机标1,至符合范围

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页