我正在使用openpyxl从excel文件中读取列。在
我已经编写了代码,把我需要的数据列放入excel,但是数据被空单元格分隔开。在
我想把这些数据分组到19组国家,这样我就可以用它来计算19个国家的平均值和标准差。在
我不想用列表片硬编码。相反,我希望使用循环将这些整数保存到一个列表或一个列表列表中,但我不确定如何保存,因为这是我第一个使用Python的项目。在
我的代码是:#Read PCT rankings project ratified results
#Beta
import openpyxl
wb=openpyxl.load_workbook('PCT rankings project ratified results.xlsx', data_only=True)
sheet=wb.get_sheet_by_name('PCT by IP firms')
row_counter=sheet.max_row
column_counter=sheet.max_column
print(row_counter)
print(column_counter)
#iterating over column of patent filings and trying to use empty cells to flag loop for it to append/store list of numbers before reaching the next non empty cell and repeat this everytime it happens(expecting 19 times)
list=[]
for row in range(4,sheet.max_row +1):
patent=sheet['I'+str(row)].value
print(patent)
if patent == None:
list.append(patent)
print(list)
这是Python的输出,让您可以直观地看到我要做的事情。在
第一列:
412
14
493
488
339
273
238
226
200
194
153
164
151
126
没有
120
没有
没有
133
77
62
79
24
0
30
20
16
0
6
9
11
没有
没有
没有
没有
608
529
435
320
266
264
200
272
134
113
73
23
12
52
21