Python Forum
How can I copy specif cell from one csv to another csv
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I copy specif cell from one csv to another csv
#1
Hi,
I want to copy 6th column from csv a to the 6th column in csv b. Besides copying, I want to add three blank rows after the copied one in csv b.

For example, if csv a 6th column has:
Output:
Event 1 p_o
csv b 6th column should have:
Output:
1 blank blank blank p_o blank blank blank
My codes copy 6th row in csv a to 4th row in csv b. It also cannot copy any word (e.g. "p_o"), but it can copy number (e.g. 1). Anyone knows how to fix these issues? Or how can I copy specific cell from one csv to the other? I am thinking if I should copy one cell from csv a and three blank cells from csv c to csv b.

Codes:
import csv
2	
3	def para(session, subj, groupnum):
4	    scorefile = str(groupnum) + str('Asns')
5	    print("scorefile: %s" % scorefile)
6	    scoreart = str(groupnum) + str('AK5s')
7	    print("scoreart: %s" % scoreart)
8	 
9	    new_score=r'K:\users\zoey\artscore\\'+scoreart+r'.csv'
10	    New_score_csv=open(new_score,'w')
11	 
12	    score_data=r'K:\users\zoey\\'+scorefile+r'.csv'
13	    print(score_data)
14	 
15	    with open (score_data) as a, open(new_score,'w') as b:
16	        b.write(next(a))
17	        ca=csv.reader(a)
18	        ca_rows=list(a)
19	        cb=csv.writer(b)
20	
21	        for row in range(len(ca_rows)):
22	            cb.writerow(([" "]*3)+[ca_rows[row][-2]]) # replace -2 with actual col if delimiter is working
23	            cb.writerow([" "]*3)

Thanks for your help! Will do next time
Reply


Messages In This Thread
How can I copy specif cell from one csv to another csv - by zoe1111 - Jan-13-2019, 08:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is the copy method name in python list copy and not `__copy__`? YouHoGeon 2 389 Apr-04-2024, 01:18 AM
Last Post: YouHoGeon
  Need to copy column of cell values from one workbook to another with openpyxl curranjohn46 3 11,431 Oct-12-2019, 10:57 PM
Last Post: curranjohn46
  using openpyxl copy the value of a cell, not the formula Pedroski55 3 31,336 Jan-07-2018, 11:44 PM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

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