csv blank fields
python at mrabarnett.plus.com
Sat Jun 27 19:06:23 CEST 2009
Mag Gam wrote:
> Sorry if I wasn't clear before.
> While reading my csv file, notice I am putting the content in an array.
> If lets say, row has nothing in it, python gives an exception.
> Instead of the exception, I would like to assign 'NULL' to row.
> Does that help?
You still didn't say what the exception was!
Anyway, if you expect 'row' to contain 11 items, then you could append
the missing ones:
for s, row in enumerate(reader):
# Fill any empty slots with "NULL".
row = [r or "NULL" for r in row]
# Append missing (empty) slots on the end.
row += ["NULL"] * (11 - len(row))
d[s] = np.array([tuple(row)], dtype=mtype)
> On Sat, Jun 27, 2009 at 10:03 AM, Peter Otten<__peter__ at web.de> wrote:
>> Mag Gam wrote:
>>> well, I am actually loading the row into a fixed width array
>>> for s,row in enumerate(reader):
>>> If there is a missing field, I get a problem in one of my rows
>> Please be specific. Describe what you want and what you get.
>> If you give code make it self-contained so that others can run it without
>> having to guess the values of the variables you introduce.
>> If an exception occurs cut and paste the traceback into your post, too.
More information about the Python-list