两个月前需求:使用python3做一个将观测数据编译产出成bufr数据的一个工具
刚刚完成初版,其中的数据文件路径和数据内容格式还需要仔细核对,但整体逻辑已实现,剩下的工作时间可能会用来完善它
Anaconda3
The open-source Anaconda Distribution is the easiest way to perform Python/R data science and machine learning on Linux, Windows, and Mac OS X. With over 11 million users worldwide, it is the industry standard for developing, testing, and training on a single machine, enabling individual data scientists to:
- Quickly download 1,500+ Python/R data science packages
- Manage libraries, dependencies, and environments with Conda
- Develop and train machine learning and deep learning models with scikit-learn, TensorFlow, and Theano
- Analyze data with scalability and performance with Dask, NumPy, pandas, and Numba
- Visualize results with Matplotlib, Bokeh, Datashader, and Holoviews
python 读取 xml
from xml.dom import minidom
def readXmlByTagName(path):
with open(path, 'r', encoding='utf8') as fh:
# 获取根节点
root = minidom.parse(fh).documentElement
# 节点类型:'ELEMENT_NODE',元素节点; 'TEXT_NODE',文本节点; 'ATTRIBUTE_NODE',属性节点
#print('节点类型:')
return root
def getElementsByTagName(root,tagName):
return root.getElementsByTagName(tagName)[0].childNodes[0].data
DataFrame --- pandas
pandas is an open source, BSD-licensed library providing high-performance, easy-to-use data structures and data analysis tools for the Python programming language.
pandas 的使用效果很腻害,在项目中主要用来读取如下图格式数据:
用到的 pandas 语法大概有:
pandas.read_table(data_path, sep=',',dtype = 'str')
用来将数据读取出来.shape[0]
用来获取数据的行数.iloc
根据 x 和 y 轴来定位元素- 文档地址
十进制转二进制
def Number2BinStr(num, size):
'''
整形转二进制字符的方法;
:param num: 需要变换的整数;
:param size:设定二进制宽度
:return:
'''
fmt = '{0:0%db}' % size
return fmt.format(num),size
字符串转二进制
def encode(s='', size=8):
str_len = len(s)
if str_len*8 <size:
for i in range(0, int((size - str_len*8)/8)):
s = s + ' '
elif str_len*8 >size:
pass
# s = s
# for i in range(0, int((str_len*8 - size)/8)):
strs = ''
for c in s:
str_byte = bin(ord(c)).replace('0b', '')
b = 8 - len(str_byte)
for i in range(0, b):
str_byte = '0'+str_byte
strs = strs + str_byte
return strs, size
求数据乘以比例因子加系数
def data_trasform_func(data, x, b):
'''
求数据乘以比例因子加系数的方法;
:param data: 数据值;
:param x:比例因子
:param b:基准值
:return:返回转换后的值;
'''
return int(data*math.pow(10, x) + b)
判断某文件夹下是否包含某个名称的文件,仅支持单个词模糊查询
#判断是否有数据文件
def search(path=".", name=""):
result = []
for item in os.listdir(path):
item_path = os.path.join(path, item)
if os.path.isdir(item_path):
search(item_path, name)
elif os.path.isfile(item_path):
if name in item:
result.append(item_path)
return result
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于