連鎖店 網(wǎng)站建設(shè) 中企動力seo搜索是什么
1、numpy.empty
作用:根據(jù)給定的維度和數(shù)值類型返回一個新的數(shù)組,其元素不進行初始化。
用法:numpy.empty(shape, dtype=float, order=‘C’)
2、logging.debug
作用:Python 的日志記錄工具,這個模塊為應用與庫實現(xiàn)了靈活的事件日志系統(tǒng)的函數(shù)與類。
圖片來源:
https://docs.python.org/zh-cn/3/library/logging.html
https://blog.csdn.net/weixin_41724044/article/details/81784974
3、assert函數(shù)
https://docs.python.org/3/reference/simple_stmts.html#assert
作用:Python assert(斷言)用于判斷一個表達式,在表達式條件為 false 的時候觸發(fā)異常。斷言可以在條件不滿足程序運行的情況下直接返回錯誤,而不必等待程序運行后出現(xiàn)崩潰的情況。
用法:assert expression
或assert expression [, arguments]
。
如果expression是True,那么什么反應都沒有。但是如果expression是False,那么會報錯AssertionError。
4、np.where函數(shù)
(1)np.where(condition):返回值是滿足condition的元素的下標;
(2)np.where(condition, x, y):返回值是一個和condition的shape相同的numpy 數(shù)組,當滿足條件condition時,返回值中的元素從x中取,否則從y中取。
5、python讀取shapefile文件
import shapefile
sh=shapefile.Reader('./shp/shapefile_file.shp')
shapefile_records=sh.records()#records,according to arcgis fileds
6、python 中兩個//表示:地板除,即先做除法(/),然后向下取整(floor)。
7、python netcdf: making a copy of all variables and attributes but one
解決方法:https://stackoverflow.com/questions/15141563/python-netcdf-making-a-copy-of-all-variables-and-attributes-but-one
代碼:
import netCDF4 as nc
toexclude = ['ExcludeVar1', 'ExcludeVar2']with netCDF4.Dataset("in.nc") as src, netCDF4.Dataset("out.nc", "w") as dst:# copy global attributes all at once via dictionarydst.setncatts(src.__dict__)# copy dimensionsfor name, dimension in src.dimensions.items():dst.createDimension(name, (len(dimension) if not dimension.isunlimited() else None))# copy all file data except for the excludedfor name, variable in src.variables.items():if name not in toexclude:x = dst.createVariable(name, variable.datatype, variable.dimensions)dst[name][:] = src[name][:]# copy variable attributes all at once via dictionarydst[name].setncatts(src[name].__dict__)
或者(測試可用):
import netCDF4 as nc
import numpy as np
toexclude = ["TO_REMOVE"]
with nc.Dataset("orig.nc") as src, nc.Dataset("filtered.nc", "w") as dst:# copy attributesfor name in src.ncattrs():dst.setncattr(name, src.getncattr(name))# copy dimensionsfor name, dimension in src.dimensions.iteritems():dst.createDimension(name, (len(dimension) if not dimension.isunlimited else None))# copy all file data except for the excludedfor name, variable in src.variables.iteritems():if name not in toexclude:x = dst.createVariable(name, variable.datatype, variable.dimensions)dst.variables[name][:] = src.variables[name][:]
代碼來源:https://stackoverflow.com/questions/15141563/python-netcdf-making-a-copy-of-all-variables-and-attributes-but-one
Python setattr() 函數(shù):
功能:setattr() 函數(shù)對應函數(shù) getattr(),用于設(shè)置屬性值,該屬性不一定是存在的。
用法:setattr(object, name, value)
8、dataframe and series
series 對象轉(zhuǎn)字符串:df[['station']] = pd.Series(df['station'], dtype="string")
篩選滿足條件的行:df_new = df.loc[df['station'].str.contains('姓名')]
Python將循環(huán)過程中產(chǎn)生的dataframe,按行合并,最終輸出一個csv文件:
merge_result = []
for file in os.listdir(csv_path):df = pd.read_csv(os.path.join(csv_path,file),header = None,names=['field1','field2'])merge_result .append(df_new)
df_all = pd.concat(merge_result , axis=0)
9、dataframe輸出csv文件,中文出現(xiàn)亂碼問題
https://blog.csdn.net/chenpe32cp/article/details/82150074
df.to_csv("result.csv",encoding="utf_8_sig")