我通过以下方式存储了约500行数据:
USGS 11456000 2000-06-01 11.0 A
USGS 11456000 2000-06-02 10.0 A
USGS 11456000 2000-06-03 9.60 A
USGS 11456000 2000-06-04 9.30 A
我想要的只是第3列和第4列(日期和度量)中的内容,但是我不确定如何调用这些特定列。
这是我尝试过的:
filename = 'STH.txt'
f = open(filename, 'r')
date = []
discharge = []
for line in f:
date.append(line.split('\t')[2])
discharge.append(line.split('\t')[3])
f.close()
time = np.array(date)
discharge = np.arra(discharge)
print(discharge)
最后我得到了一对空括号。
答案 0 :(得分:3)
最简单的阅读方法可能是通过像这样的大熊猫:
LoggerContext context = (LoggerContext)LoggerFactory.getILoggerFactory();
context.putProperty("global", "value");
答案 1 :(得分:0)
您可以使用熊猫库
import pandas as pd
dataFrame = pd.read_csv("./demo1.txt", sep="\t")
dataFrame.columns =['name','num', 'date', 'measurement'] #here you
# can name
#the column header
print(dataFrame['date'])
print(dataFrame['measurement'])
答案 2 :(得分:0)
filename = 'STH.txt'
f = open(filename, 'r')
date = []
discharge = []
for line in f:
date.append(line.split()[2])
discharge.append(line.split()[3])
f.close()
time = np.array(date)
discharge = np.arra(discharge)
print(discharge)
我建议您使用.split()而不是split('\ t')