表格内容大致如下: 一共两列(Year | SIF )Year:2001 -2020
目的:求每一年对应的SIF 平均值
1 import pandas as pd
2 import numpy as np
3
4 file = pd.read_csv('csv存放路径')
5 a = []
6
7 for year in range(2001,2021):
8 sif = file[['SIF']][file['Year'] == year]
9 mean_sif = np.average(sif) # 一年sif平均
10 a.append(mean_sif) # 将每一年的平均值放在一个数组里面
11
12 # 新建csv
13 name = ['mean_sif']
14 new_file = pd.DataFrame(cloumns = name, data = a)
15 new_file.to_csv('新的csv存放地址',encoding = 'gbk')