-1
您好所有我是新来的Python和真正需要帮助的打开文件,并在文件中选择特定的列
我有一组数据如下 所有大的值是1列和XX.X是列2 19600110 28.6 19600111 28.9 19600112 29.2 19600113 28.6 19600114 28.6 19600115 28.4 19600116 28.6 19600117 28.6
存储为station.txt
我试图让python只提出数据的第一列(19600115等),它被标记为dates.I打开文件,我使用for循环尝试只打开第1列。我不知道我要去的地方错了任何帮助,将不胜感激
高清load_dates(站):
“”“负载站的日期,不包括站的温度数据”“”
f = open(stations[0] + '.txt', 'r')
#create a for loop and open first column of data which are the dates
#close the file and return body of dates
dates = []
for line in f:
dates.append(lines(7))
f.close()
return dates
每一行都是“19600110 28.6”,你应该将它分割为.dates = [line.split()[0])。 – sinceq