I am very new to Python and I have been trying to detect missing data in lists created from data in imported csv files so that I can plot the series using matplotlib without getting an error.
I show you what I have:
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
I need to mask the empty values e.g. ” so that I can plot the series without errors. Any suggestion to solve this problem?
Regards…
What do you mean by mask? Remove? If so, try the following:
Edit:
I’m not used to numpy, but maybe this is what you are searching for: