python 读取二进制 bin 文件,解析为数字信息, 缩放到某一范围且画图

# 读取数据 bin 文件
import pandas as pd
import numpy as np
import os
import matplotlib.pyplot as plt
import struct

def read_data():
    file_dir = './'
    file_name = 'Raw Data-1-1Y520230404-10-14-03_8192.bin'
    file_path = os.path.join(file_dir, file_name)
    data_bin = open(file_path, 'rb+')
    data_size = os.path.getsize(file_path)
    data_list = []
    for i in range(data_size):
        data_i = data_bin.read(1) # 每次输出一个字节
        #print(data_i)
        num = struct.unpack('b', data_i) # B 无符号整数,b 有符号整数
        data_list.append(num[0])
        #print(num[0])
    data_bin.close()
    from sklearn import preprocessing
    min_max = preprocessing.MinMaxScaler(feature_range=(-1, 1)) # 缩放到[-1, 1], 增强数据的稳定性
    data_list_scale = min_max.fit_transform(np.array(data_list).reshape(-1, 1))
    data_list_scale_part = data_list_scale[:2000]
    wave_del_zero(data_list_scale_part)
    plt.plot(data_list_scale_part)
    plt.show()

你可能感兴趣的:(python,DataFrame操作)