Python Forum
Adding Columns to CSV using iterator
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding Columns to CSV using iterator
#1
Here is what I need to do.

1. I have an existing CSV file with 12 columns in it containing financial information. This CSV is sorted. I need to ADD two columns: 'product item number' (a 7 digit int) and 'product item number ID' (a 6 digit int).

2. Once I add the two columns, I need to write a number into the first row for that column and then add 'one' to the number in each subsequent row cell in that column so that each subsequent cell is one more than the previous, i.e. the number increases sequentially with each row in the sort. I need to do this for both 'product item number' and 'product item number ID'.

My main problem is putting the csv writer into a loop so I can increment the variable and write it into subsequent cells in the loop. I have looked at DictWriter, pandas concat (axis 1) and similar. Any help would make my week....thank you very much!
Reply


Messages In This Thread
Adding Columns to CSV using iterator - by pstarrett - Jan-09-2018, 05:00 AM
RE: Adding Columns to CSV using iterator - by buran - Jan-09-2018, 08:19 AM
RE: Adding Columns to CSV using iterator - by buran - Jan-16-2018, 07:10 AM
RE: Adding Columns to CSV using iterator - by buran - Jan-19-2018, 07:17 AM
RE: Adding Columns to CSV using iterator - by buran - Jan-21-2018, 07:04 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Merging rows and adding columns based on matching index pythonnewbie78 3 828 Dec-24-2023, 11:51 AM
Last Post: Pedroski55
  numpy adding columns rwahdan 4 2,346 Sep-21-2021, 08:25 PM
Last Post: deanhystad
  Tesseract-ocr ->iterator.WordFontAttributes() does not work Maia07 0 3,428 Sep-01-2018, 02:43 PM
Last Post: Maia07

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020