如何将一组数据从excel文件复制到另一个文件,而不复制nan数据?

时间:2019-01-28 03:45:08

标签: python excel

我想将一组数据从一个Excel文件复制到另一个Excel文件,如果数据为空,则不要将数据复制到另一个Excel文件。我使用了一个numpy数组从excel文件中获取数据,并判断该单元格是一个数字而不是nan,如果不是nan,则不要将单元格值复制到另一个文件,但是不能正常运行,我的excel源文件有30张,如何获取一个容器来显示源文件的每张纸

import openpyxl
import numpy as np
wbS = openpyxl.load_work('path to the Source file')
wb  = openpyxl.load_work('path to the destination excel file')
d = 'B'
P = np.zeros(3)
for i in range(1,31)
    for j in range(3)
        P[j] = wbS[i]['%s8'%chr(ord(d)+j)].value
        if isinstance(P[j],(int,float)):
           wb[i]['%s2'%chr(ord(d)+j)] = wbS[i]['%s8'%chr(ord(d)+j)].value
wb.save('path and name for the destination excel file)

我的问题是:

1:当isinstance(P[j],(int,float))从Excel单元格中获取nan或空数据时。它返回一个true,我用

if not np.isnan(P[j]):
     # wb[i]['cell'] = wbS[i]['cell'].value

遇到nan数据时,也像isinstance进入if语句 我的代码哪里错了?

2:如何使用对象来表示每张纸 我的源excel文件工作表对象处于一个循环中?当我不使用直接分配

# wb[i]['cell'] = wbS[i]['cell'].value

0 个答案:

没有答案
相关问题