473,320 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Appending N/A to blank strings

I have a list of numbers imported from excel, an example line looks like this...

70609,86,91,,66,66,

I would like a N/A to be inserted in between the two commas and after the last one.
This is the code I have so far, but I haven't gotten it to work.

Expand|Select|Wrap|Line Numbers
  1. f = open("C:\users\cory\desktop\code\Verification.csv")
  2. dd = {}
  3. keys = f.readline().strip().split(',')
  4.  
  5. for key in keys:
  6.     dd.setdefault(key, [])
  7.  
  8. for line in f:
  9.     elements = line.strip().split(',')
  10.     for i, item in enumerate(elements):
  11.         if element == "":
  12.             dd[keys[i]].append("N/A")            
  13.         else:
  14.             dd[keys[i]].append(int(item))
  15. f.close()
  16.  
  17. for key in keys:
  18.     print "%s: %s" % (key, dd[key])
  19.  
Jul 6 '09 #1
2 1764
bvdet
2,851 Expert Mod 2GB
You are close. Instead of
Expand|Select|Wrap|Line Numbers
  1.         if element == "":
use this:
Expand|Select|Wrap|Line Numbers
  1.         if item == "":
OR
Expand|Select|Wrap|Line Numbers
  1.         if not item:
Jul 6 '09 #2
Ah. So close! Thanks!
Jul 7 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Shannan Casteel via AccessMonster.com | last post by:
I need some code to append several strings together, and insert those strings into a text box. But the insertion should only happen when a particular check box has been checked. For instance, I...
1
by: mikemac76 | last post by:
I am trying to build a test harness to practice appending strings to an rtf string. I am doing this to simulate the string I'll be sending over the wire and receiving on the other end of an IM...
13
by: Shwetabh | last post by:
Hi, I wanted to know if it is possible to do to append two tables into a third table. For example, consider these two tables Table 1...
1
by: Ron Adam | last post by:
In my program I have a lot of statements that append elements, but sometimes I don't want to append the element so it requres an if statement to check it, and that requires assigning the returned...
2
by: Miguel | last post by:
I have a problem in appending notes from a new notes memo field to one that is read-only, i.e., field enabled, but locked. I have seen many messages touching on this subject but cannot find the...
4
by: MGM | last post by:
Hello everyone, I once again have a problem :p I need to write a query to get the total amount of rows in a table. Problem is, the table name is dynamic and part of its value is stored in...
7
by: Andrus | last post by:
How to create format string for decimal data type which shows blank for zero and default format otherwize ? I tried format string "f;f;#" but this shows f for nonzero numbers. Andrus. ...
5
by: David E. Ross | last post by:
I'm getting occasional visits to my Web site from applications with blank UA strings. I would like to block such accesses because they violate various RFCs and might represent attempted hostile...
0
by: nbardach | last post by:
Hope this finds everyone well. Happy New Year! I'm trying to build a Loop for a set of dropdown menus I'm inserting into a form. Basically, the client has to be able to select 1 to 20 donors...
1
by: KiddoGuy | last post by:
I am trying to build a string character by character. However, when I use the overloaded += or string.append() method, the character replaces the one before it rather than appending to it so I am...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.