Python 和 Excel,计算细胞数
Python with Excel, counting the cells
我确实有一个 excel sheet,里面有 30000 行。我想用例如 #1 对前 5 行进行分类。第二个第 5 行带有 #2,依此类推,直到达到 30000 行。我怎样才能用 excel sheet 做到这一点。
lst1 = []
classifier = 0
while classifierOne <= 30000:
if classifier <= 5:
lst1.append(1)
if classifier > 5 and classifier<=10:
lst1.append(2)
::
::
::
::
::
::
::
::
classifierOne +=1
# do this until I reach 30000 which is not an efficient way to do.
print(lst1, classifierOne)
df = DataFrame({'':lst1})
df.to_excel('list.xlsx', sheet_name='sheet1', index=False)
我尝试了很多方法但是我找不到有效的方法来做到这一点。感谢您的帮助。
您可以使用平面双列表理解轻松生成这样的列表,将每个数字重复五次:
n = 5
lst1 = [i for i in range(1,30000//n+1) for _ in range(n)]
发出 30000/5 个数字(6000),每个数字重复 5 次(所以 30000 行)。
结果:
[1,
1,
1,
1,
1,
2,
2,
2,
2,
2,
3,
3,
3,
3,
3,
4,
4,
4,
4,
4,
5,
5,
5,
5,
5,
etc...
我确实有一个 excel sheet,里面有 30000 行。我想用例如 #1 对前 5 行进行分类。第二个第 5 行带有 #2,依此类推,直到达到 30000 行。我怎样才能用 excel sheet 做到这一点。
lst1 = []
classifier = 0
while classifierOne <= 30000:
if classifier <= 5:
lst1.append(1)
if classifier > 5 and classifier<=10:
lst1.append(2)
::
::
::
::
::
::
::
::
classifierOne +=1
# do this until I reach 30000 which is not an efficient way to do.
print(lst1, classifierOne)
df = DataFrame({'':lst1})
df.to_excel('list.xlsx', sheet_name='sheet1', index=False)
我尝试了很多方法但是我找不到有效的方法来做到这一点。感谢您的帮助。
您可以使用平面双列表理解轻松生成这样的列表,将每个数字重复五次:
n = 5
lst1 = [i for i in range(1,30000//n+1) for _ in range(n)]
发出 30000/5 个数字(6000),每个数字重复 5 次(所以 30000 行)。
结果:
[1,
1,
1,
1,
1,
2,
2,
2,
2,
2,
3,
3,
3,
3,
3,
4,
4,
4,
4,
4,
5,
5,
5,
5,
5,
etc...