如何获取每个字符串中的数字总和
到目前为止,这就是我所做的:
我已经将Excel数据转换为列表
将所有小时数据列表组合到一个
使用的拆分函数中,以删除使用的数字和使用的数字之间的所有逗号和空格,
以每12个ZEROS将数据组分开以将数据组分开
现在,我试图将所有分开的数字总结到每个字符串中,该怎么做?
这是我的代码:
df = pd.read_excel("2010.xlsx")
df2 = df.to_numpy()
df3 = df2[0:366, 1:25]
list1 = df3.tolist()
list2 = (list(itertools.chain.from_iterable(list1)))
b = ''.join(str(list2).split(','))
c = ''.join(str(b).split(' '))
e = c.split('0'*12)
打印此代码提供类似:
['[','','000000000100111101',',',','000000112111111111110000000000001',',','',','',',',',',',',',',',',',',',',',',',',' ','','','','','','','','','','',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',',', ',','
' '00001121121111111111000000001'等等
This is what I have done so far:
I have converted excel data to list
combined all the hourly data lists into one list
used split function to remove all commas and spaces between the numbers
used split function again to separate group of data by every 12 zeros
Now I'm trying to sum all the numbers that are separated into each string how would I do this?
Here is my code:
df = pd.read_excel("2010.xlsx")
df2 = df.to_numpy()
df3 = df2[0:366, 1:25]
list1 = df3.tolist()
list2 = (list(itertools.chain.from_iterable(list1)))
b = ''.join(str(list2).split(','))
c = ''.join(str(b).split(' '))
e = c.split('0'*12)
printing this code gives something like:
['[', '', '000000000100111101', '', '', '0000112112111101011100000000001', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '0000002433151111000001223221', '', '', '', '', ]
so I'm trying to add all the numbers in '000000000100111101' and '0000112112111101011100000000001' and so on
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定这是您想要的,但请尝试此
产生此输出
Not sure this is what you want, but try this
producing this output