python - Trouble in saving a list to csv -
I am saving a list from a csv module using a writer's feature in a CSV. Something went wrong when I opened the last file in MS Office Excel. Before I have to face this problem, the main problem I am trying to deal with is that the list is being saved in every row, saving every row in line one in line 1, I made some minor changes Now it has happened that I am very confused as a novice dragon man.
Import CSV inputfile = open ('small.csv', 'r') header_list = [] header = inputfile.readline () header_list input (header) input for row in input_lines = []: Input_lines.append (line) inputfile.close () AA_list = [] for the range I (0, lane (input_line)): if (input_lines [i] .split (',') [4]) == 'AA': # Column 4 has different names including 'AA' AA-list .append (input_lines [i]) full_list = header_list + aa_list result file = open ("aa 2013.csv", "w +) Wr = Csv.writer (resultFile, delimiter = ',') wr.writerow (full_list) Thanks!
Update: The full_list looks like this: ['1,2,3," MEM ", ...]
UPDATE2 (APR. 22nd): Now I found three cells of data (heading in A1 and remaining A2 and A3 respectively), the same line is obviously, new signals are not working for three items in a large list. The more specific question is how do I save the record list with '\ n' behind each record?
UPDATE3 (APR 23rd): Original file Importing module
CSV module is not enough, you still have to use it now, you Each row is added as a whole string in your list instead of a list of fields. Input file as Start with (
: Reader = csv.reader (inputfile, delimiter = "," ) Header_list = next (reader) input_lines = list (reader) now includes all the headers in header, and all in input_lines There is a nested list of rows, divided into each column. I think the rest should be very simple.
Comments
Post a Comment