首页 > 解决方案 > 用python计算excel列中的元素

问题描述

我正在学习python。我有一个 excel 文档,其中一个第一列包含多个元素(第 1 列包含“a”和“b”),第二列包含第 1 列中元素的值:

Column 1  Column 2
   a        10
   a        100
   b        1
   b        15
   b        10

我正在尝试在 Python 3 中编写一个脚本,其中我得到以下内容:

Column 1  Column 2
   a        110     --> Sum of all elements in previous column 1 for a
   b        26      --> Sum of all elements in previous column 1 for b

有什么建议么?谢谢。

我已经尝试过使用列表和字典,但没有得到合理的答案。

Column 1  Column 2
   a        110     --> Sum of all elements in previous column 1 for a
   b        26      --> Sum of all elements in previous column 1 for b
from xlwt import Workbook
i=0
for element in Column_1:
    sheet1.write(i,0,element)
    i +=1

标签: python-3.x

解决方案


推荐阅读