- 论坛徽章:
- 0
|
最近接触到用python打开文件以及csv模块
我有一个.csv文件 部分内容如图
分别是Country Name, Country Code,Indicator Name,Indicator Code,和1960年一直到2015年的数据
现在我要输入我想要查询的Indicator Name,然后输出对应的最大值以及最大值所发生的年份和国家。如果有相同的就全部输出
既要对比所有年份里的最大值,还要比较每个国家的最大值。
如输入 Age population, age 12, female, interpolated,所得到的是13193254,对应的是2000: [’China’]
firstyear = 1960
number_of_years = 56
max_value = None
countries_for_max_value_per_year = {} #每年最大值的国家和年份,然后通过 sorted排列输出年份和国家
print('The maximum value is:', max_value)
print('It was reached in these years, for these countries or categories:')
for year in sorted(countries_for_max_value_per_year):
print(' {}: {}'.format(year, countries_for_max_value_per_year[year]))
with open(filename) as csvfile:要如何查询。。。
谢谢各位大神!求教!
|
|