读取循环中的数据错误“必须是str,而不是数字.int32"

2024-05-19 12:35:25 发布

您现在位置:Python中文网/ 问答频道 /正文

Python3

我需要用这个数据网站绘制8月3日到8月10日的臭氧时间序列。我需要把数据“缝合”在一起。你知道吗

http://skywatch.colorado.edu/data/ozone_18_09_03.dat 所以现在我有

pre= 'http://skywatch.colorado.edu/data/ozone_18_09_0'

ozone = []
utc = []
dates = np.arange(3,10,1)


for date in dates: 
    url = pre + dates[i] + ".dat"
    lines = urllib.request.urlopen(url).readlines()
    for line in lines: #for x number of times (however many lines appear in the dataset)
        entries = line.decode("utf-8").split("\t")
        if entries[0][0] != ';': #if there are entries that do not have a semicolon 
            utc.append(float(entries[0][0:2]) + \
                   float(entries[0][3:5])/60. + \
                   float(entries[0][6:8])/3600.)
        #converts the UTC time variable into a float and adds it to the list 'utc'
            ozone.append(float(entries[1])) 

当我试着运行这个时,我得到了一个错误

--->;9 url=pre+日期[i]+“.dat”

TypeError:必须是str,而不是数字.int32 注意如何处理这个问题


Tags: the数据inhttpurlforfloatpre
1条回答
网友
1楼 · 发布于 2024-05-19 12:35:25

我认为您可能需要显式地转换数字.int32对象到字符串,因为numpy很可能没有为other: str定义__add__(self, other)。你知道吗

另外,您使用变量datedates中迭代,因此您可以使用如下内容:

url = pre + str(date) + ".dat"

相关问题 更多 >