-4- 更新一些處理數(shù)據(jù)中可能會用到的Function
def Copy_attribute(self, data, data_copy):
'''
Function:This script is used to refresh data properties.
Copy the properties of the data_copy to the data_new and the data data to the data_new.
Author:xiaohuoya
Date:2020-05-20
'''
data_new = data_copy.copy()
data_new.values = data
return data_new
def Read_region(self, data, region_shp):
'''
Function:This script is used for irregular region data reading, such as reading data for the Yangtze River Delta region.
Author:xiaohuoya
Date:2020-05-20
'''
import geopandas
import salem
region_shp = geopandas.read_file(region_shp)
data_region = data.salem.roi(shape=region_shp)
return data_region
def Data_to_Excel(self,data, file_name,header):
'''
Function:This script is used to write data to Excel.
Author:xiaohuoya
Date:2020-05-21
Eg: -1- data: the data
-2- file_name: the file name
-3- sheet_name: the sheet name
-4- header: the header('a','b','c')
'''
import pandas as pd
import openpyxl
data = pd.DataFrame(data)
writer = pd.ExcelWriter(file_name)
data.to_excel(writer, self.sheet_name, float_format='%.4f',header=header)
writer.save()
writer.close()
1.Copy_attribute函數(shù)用于復(fù)制一個數(shù)據(jù)的屬性到另一個數(shù)據(jù),例如data(time,lat,lon),data_copy(time,lat1,lon1),data_new(time,lat1,lon1)其中的數(shù)據(jù)為data
2.Read_region函數(shù)引用salem、geopandas可以用來處理特定地形的數(shù)據(jù),導(dǎo)入對應(yīng)的地形shp文件即可
3.Data_to_Excel函數(shù)可以將數(shù)據(jù)輸出成excel