I have several tabular text files in a folder.The data in the first column are strings,second and third column integers.How can I read them all in and write the first column and the second column edited(say divided by two) into a new tabular text file? I've just begun learning python so please kindly give example code if possible.Thanks.
This snippet might give you some idea
# terrible code for educational purposes only!
in_stream = open(filename_in)
out_stream = open(filename_out, 'w')
output = csv.writer(out_stream)
for col_string, col_value1, col_value2 in csv.reader(in_stream):
new_row = [col_string, col_value1 / 2, col_value2]
output.write(new_row)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.