python 词典的序号_使用Python中的字典将月份编号转换为月份名称

我试图将一组数字(1-12)转换成相应的月份(1-12月),但是我必须使用字典。在

我有一个数组形式的月份,我得到一个错误,要么是“TypeError:only length-1数组可以转换为Python标量”或“TypeError:'dict'object is not callable”outfile = ("heathrow_weather.npz")

#find out names of arrays

ph_read= np.load(outfile)

print(ph_read.files)

#assign arrays to a variable

max_temp=ph_read['t_max']

month_no=ph_read['month']

year_no=ph_read['year']

rainfall=ph_read['rainfall']

min_temp=ph_read['t_min']

outfile = open("weather_tables.txt", "w")

outfile.write("Month Year Min Temp Max Temp Rainfall\n")

outfile.write(" (°C) (°C) (mm)\n")

for t0, t1, t2, t3, t4 in zip(month_no, year_no, max_temp, min_temp, rainfall):

string = str(t0)+" "+str(t1)+" "+str(t2)+" "+str(t3)+" "+str(t4)+"\n"

outfile.write(string)

outfile.close()

所有这些代码都能工作,所以只是为了上下文。下一个就是我正在挣扎的地方

^{pr2}$

我试过使用:month_int=int(month_no)

month=MonthDict(month_int)

但是我得到了长度-1的误差。在

我还试图:for integer in month_no:

month_no = MonthDict(month_no)

但这会产生“dict object not callable”错误


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部