[英]How to read 2 columns of .txt file & store it in x & y variables in python
This is the data of.txt file.(2 columns)这是.txt文件的数据。(2列)
6.1101,17.592
5.5277,9.1302
8.5186,13.662
7.0032,11.854
5.8598,6.8233
8.3829,11.886
7.4764,4.3483
8.5781,12.0
6.4862,6.5987
5.0546,3.8166
5.7107,3.2522
you can use csv reader
您可以使用
csv reader
import csv
x = []
y = []
with open('file.txt') as f:
reader = csv.reader(f)
for row in reader:
x.append(float(row[0]))
y.append(float(row[1]))
Output : Output :
>>x
[6.1101, 5.5277, 8.5186, 7.0032, 5.8598, 8.3829, 7.4764, 8.5781, 6.4862, 5.0546, 5.7107]
>>y
[17.592, 9.1302, 13.662, 11.854, 6.8233, 11.886, 4.3483, 12.0, 6.5987, 3.8166, 3.2522]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.