我对Python非常陌生,我一直在尝试检测从导入的csv文件中的数据创建的列表中缺少的数据,这样我就可以使用matplotlib绘制序列而不会出现错误。在
我向你展示我所拥有的:
import numpy as np
# import matplotlib.pyplot as plt
import csv
from pylab import *
res = csv.reader(open('cvs_file_with_data.csv'), delimiter=',')
res.next() # do not read header
ColOneData = []
ColTwoData = []
ColThreeData = []
for col in res:
ColOneData.append(col[0])
ColTwoData.append(col[1])
ColThreeData.append(col[2])
print ColOneData # I got here the following ['1', '2', '3', '4', '5']
print ColTwoData # I got here the following ['1', '2', '', '', '5']
print ColThreeData # I got here the following ['', '', '3', '4', '']
ColTwoData_M = np.ma.masked_where(ColTwoData == '', ColTwoData) # This does not work
我需要屏蔽空值,例如''。有什么解决这个问题的建议吗?在
问候。。。在
你说的面具是什么意思?删除?如果是,请尝试以下操作:
编辑:
我不习惯裸体,但也许这就是你想要的:
^{pr2}$如果要向空节点添加填充值,可以执行以下操作:
如果这就是你要找的结果,你可以
map(defaultIfEmpty,ColOneData)
然后是coltwoadata,等等Jose,如果你想把column1和column2对应起来,而不是让空项引起错误,那么就必须删除column2中的空项以及column1中的相应项。下面这样的函数应该可以做到这一点。在
相关问题 更多 >
编程相关推荐