Home > other >  Python
Python

Time:09-22

How to save the following list in the CSV file, where the intermediate steps need to change? Never success

CodePudding user response:

Look at the code can be written to

But list1 final value is the line in Japan, you are only in a CSV file into this line,

CodePudding user response:

The
reference 1 floor So. Ne response:
see code can be written to

But list1 final value is the line in Japan, you are only in a CSV file into this line,

The rightness??? Is there any way to value generation in the list

CodePudding user response:

Method one:

To establish an empty list, all the list1 deposit, then the writer. Writerows (list2)
 
The import CSV

List2=[]
With the open (' D:/covid1. TXT ', 'r +') as f:
For the line in f.r eadlines () :
List1=line [: - 1]. The split (', ')
List2. Append (list1)
Print (list1)

With the open (' D:/covid. CSV ', 'w +') as f1:
Header=[' area ', 'new' and 'current' and 'total', 'cure', 'death']
Writer.=the CSV writer (f1)
Writer. Writerow (header)
Writer. Writerows (list2)

CodePudding user response:

The read and write bai
Writer. Writerow (header)
Writer. Writerows (list1)
Inserted into the first

CodePudding user response:

refer to the second floor cjy__ response:
Quote: reference 1 floor So. Ne response:
see code can be written to

But list1 final value is the line in Japan, you are only in a CSV file into this line,

The rightness??? Is there any way to the list of value generation in yao

The open function of writing mode from 'w +' to 'a +'