Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
csv help
#1
I'm trying to take a string value from a cell in one csv file and write it to a cell in a different csv file.
The problem I'm running into is that when the string is written into the second csv file, it is being split into two cells.
For example, in the first csv file the value in the cell is '20'. When it is written to the second csv file '2' goes in one cell and '0' goes in a second cell. How do i get '20' to go into one cell? below is my code. thanks for any help!

import csv

f_read_name = 'csv_test.csv'
f_write_name = 'csv_test_write.csv'

with open(f_read_name) as f_rn:
	reader = csv.reader(f_rn)
	header = next(reader)
	
	size = []
	
	for row in reader:
		size.append(row[0])
		
	last = size[-1]
	
with open(f_write_name, 'a', newline='') as f_wn:
	write_file = csv.writer(f_wn)
	write_file.writerow(last)
Reply
#2
Try write_file.writerow([last]) perhaps.
Reply
#3
that worked, thanks!
Reply


Forum Jump:

User Panel Messages

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